#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long N, Q;
  cin >> N;
  vector<int> A(N);
  for (long long i = 0; i < long long(N); i++) cin >> A[i];
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (long long i = 0; i < long long(Q); i++) cin >> B[i] >> C[i];
  long long sum = accumulate(A.begin(), A.end(), 0);
  for (long long i = 0; i < long long(Q); i++) {
    long long kosu = 0;
    for (long long j = 0; j < long long(N); j++) {
      if (B[i] == A[j]) {
        A[j] = C[i];
        kosu++;
      }
    }
    long long diff = kosu * (C[i] - B[i]);
    sum += diff;
    cout << sum << endl;
  }
  return 0;
}
