#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    long long ai;
    cin >> ai;
    a[i] = ai;
    sum += ai;
  }
  int q;
  cin >> q;
  vector<pair<int, int> > bc(q);
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    bc[i] = make_pair(b, c);
  }
  int erased[100009];
  int cntMemo[100009];
  for (int i = 0; i < (int)(q); i++) {
    int b = bc[i].first, c = bc[i].second;
    if (erased[b] == 1) {
      cout << sum << endl;
      continue;
    }
    int b_cnt = count(a.begin(), a.end(), b) + cntMemo[b];
    sum += (long long)b_cnt * (bc[i].second - b);
    cntMemo[c] += b_cnt;
    cntMemo[b] = 0;
    erased[b] = 1;
    erased[c] = 0;
    cout << sum << endl;
  }
  return 0;
}
