#include <bits/stdc++.h>
using namespace std;
using p = pair<int, int>;
signed main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) cin >> A[i];
  long long Q;
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    long long B, C;
    cin >> B >> C;
    for (long long j = 0; j < N; j++) {
      if (A[j] == B) {
        A[j] = C;
      }
    }
    long long Asum = accumulate(A.begin(), A.end(), 0);
    cout << Asum << endl;
  }
  return 0;
}
