#! /usr/bin/perl

	# Grab pairs of arguments from @ARGV,
	# saving them in arrays @oldz and @newz.
$npairs = 0;
while(@ARGV >= 2) {
    $oldz[$npairs] = shift(@ARGV);
    $newz[$npairs] = shift(@ARGV);
    $npairs++;
}

while(<>) {	# For each line of input,

    if(/[()]/) { # if the line contains any parentheses,
	print;  # then copy it verbatim to output
	next;   # and proceed to processing the next line.
    }

    @fields = split(' ');   # split the line into blank-separated fields
    if(@fields != 4) {	   # if there aren't four of them,
	print;		   # copy verbatim, etc.
	next;
    }

    # Is this Z value one of the ones we want?
    # Just use numerical comparison, not string equality,
    # so "1.00" is a match for "1".

    for($i = 0; $i < $npairs; $i++) {
	if($fields[3] == $oldz[$i]) {
	    $fields[3] = $newz[$i];
	    last;	    # like "break" in C -- stop p
	}
    }

    # Whether we changed it or not,
    # print this "i x y z" line out,
    # joining the fields with a blank between each one.

    print join(" ", @fields), "\n";
}
