#!/usr/bin/perl

$line = <STDIN>;
$line =~ /(\d+)/;
$scenarios = $1;
while ($scenarios > 0) {
    $scenarios--;
    # handle one scenario
    $line1 = <STDIN>; #chomp $line1;
    $line2 = <STDIN>; chomp $line2;
    $line1 =~ /[\w\s]*\<([\w\s]*)\>([\w\s]*)\<([\w\s]*)\>([\w\s]*)/;
    $s2 = $1;
    $s3 = $2;
    $s4 = $3;
    $s5 = $4;
    # do replacements
    $line1 =~ s/\<//g;
    $line1 =~ s/\>//g;
    $line2 =~ s/\.\.\./$s4$s3$s2$s5/;
    print $line1;
    print $line2;
}




