#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const AMAX = 1e5 + 11;
int freq[AMAX];
ll sum;
void update(int b, int c) {
  sum -= b * freq[b];
  sum += freq[b] * c;
  freq[c] += freq[b];
  freq[b] = 0;
}
inline ll query(void) { return sum; }
int main(void) {
  int n, q, ai, b, c;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> ai;
    freq[ai]++;
    sum += ai;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    update(b, c);
    cout << query() << endl;
  }
  return 0;
}
