#include <bits/stdc++.h>
using namespace std;
void print(vector<int> x) {
  for (int n = 0; n < x.size(); n++) {
    cout << x.at(n) << " ";
  }
  cout << endl;
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int n;
  int64_t sum = 0;
  for (n = 0; n < N; n++) {
    cin >> A.at(n);
    sum += A.at(n);
  }
  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (n = 0; n < Q; n++) {
    cin >> B.at(n);
    cin >> C.at(n);
  }
  for (n = 0; n < Q; n++) {
    int b = B.at(n);
    int c = C.at(n);
    int diff = c - b;
    for (int m = 0; m < A.size(); m++) {
      if (A.at(m) == b) {
        A.at(m) = c;
        sum += diff;
      }
    }
    cout << sum << endl;
  }
}
