#include <bits/stdc++.h>
int main() {
  int N;
  scanf("%d", &N);
  int A[N + 1];
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[N]);
  }
  int Q;
  scanf("%d", &Q);
  for (int i = 1; i < Q; ++i) {
    int B, C, sum = 0;
    scanf("%d %d", &B, &C);
    printf("%d %d\n", B, C);
    for (int j = 1; j <= N; ++j) {
      if (A[j] == B) A[j] = C;
      printf("%d\n", A[j]);
      sum += A[j];
    }
    printf("%d\n", sum);
  }
}
