#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
int N, Q, A[MAX_N], B[MAX_N], C[MAX_N];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) scanf("%d %d", &B[i], &C[i]);
  int n = 0;
  while (Q--) {
    int b = B[n], c = C[n], sum = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] == b) A[i] = c;
      sum += A[i];
    }
    cout << sum << endl;
    n++;
  }
  return 0;
}
