#include <bits/stdc++.h>
using namespace std;
long long sum(vector<int> x) {
  int ret = 0;
  for (int i : x) ret += i;
  return ret;
}
int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (int)(N); i++) cin >> A[i];
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  vector<long long> ans(Q + 1);
  for (int x : A) ans[0] += x;
  for (int i = 0; i < (int)(Q); i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < (int)(Q); i++) {
    int counter = 0;
    for (int j = 0; j < (int)(N); j++) {
      if (A[j] == B[i]) {
        A[j] = C[i];
        counter++;
      }
    }
    ans[i + 1] = ans[i] + counter * (C[i] - B[i]);
  }
  for (int i = 1; i <= Q; i++) {
    cout << ans[i] << endl;
  }
}
