#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a, q, b, c, sum = 0;
  cin >> n;
  vector<int> v(1000000);
  for (int i = 0; i < n; i++) {
    cin >> a;
    v[a]++;
    sum += a;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    int w;
    w = v[b];
    v[b] = 0;
    v[c] += w;
    sum = sum - (b * w) + (c * w);
    cout << sum << endl;
  }
  return 0;
}
