#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, B, C, n, q;
  long long int S;
  int* A;
  cin >> N;
  A = new int[N];
  for (n = 0; n < N; n++) cin >> A[n];
  cin >> Q;
  for (q = 0; q < Q; q++) {
    S = 0;
    cin >> B >> C;
    for (n = 0; n < N; n++) {
      if (A[n] == B) {
        A[n] = C;
      }
      S += A[n];
    }
    cout << S << endl;
  }
  delete[] A;
  return 0;
}
