#!/usr/bin/perl

while (<>) {
  if (/G(\d)R(\d)C(\d)/) {
    $grid = $1;
    $row = $2;
    $col = $3;
    /N(\d)/;
    $num = $1;
    $answer[$grid][$row][$col] = $num;
  }
}

for $grid (1..4) {
  for $row (1..9) {
    for $col (1..9) {
      print $answer[$grid][$row][$col];
    }
    print "\r\n";
    print "\r\n";
  }
  print "\r\n";
}

  for $col (1..9) {
    print "\tC$col";
  }
print "\r\n";
print "\r\n";
  for $row (1..9) {
    print "R$row\t";
    for $col (1..9) {
      print 
$answer[1][$row][$col] +
$answer[2][$row][$col] +
$answer[3][$row][$col] +
$answer[4][$row][$col];
      print "\t";
    }
print "\r\n" if ($row % 3 == 0);
    print "\r\n";
  }
