#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q, b, c, x, sum, w;
  cin >> n;
  map<int, int> m;
  sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += x;
    m[x]++;
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> b >> c;
    sum += m[b] * (c - b);
    w = m[b];
    m.erase(b);
    m[c] += w;
    cout << sum << "\n";
  }
  return 0;
}
