#include <bits/stdc++.h>
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    map<int, int> in;
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      in[a] = b;
    }
    int m;
    cin >> m;
    map<int, int> out;
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      out[a] = b;
    }
  }
}
