#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  scanf("%d\n", &N);
  vector<int> A(N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  scanf("\n%d\n", &Q);
  for (int i = 0; i < Q; i++) {
    long long ans = 0;
    int b, c;
    scanf("%d%d\n", &b, &c);
    for (int j = 0; j < N; j++) {
      if (A[j] == b) A[j] = c;
      ans += A[j];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
