
import std.stdio;
import std.string;
import std.algorithm;
import std.array;
import std.conv;

void main() {
  int[int] data;
  int[int] res;
  bool second_time = false;
  while(true) {
    string line = readln.chomp;
    if (stdin.eof) break;
    if (line.length == 0) {second_time = true; continue;}
    auto i = line.split(",").map!(to!(int)).array;
    if (second_time) {
      if (i[0] in data) res[i[0]] = ++data[i[0]];
    }
    else {
      data[i[0]] = 1;
    }
  }
  foreach(k; res.keys.sort) {
    writeln(k, " ", res[k]);
  }
}