#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, q, s = 0;
  cin >> n;
  int a[n];
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    ++m[a[i]];
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int x, y;
    cin >> x >> y;
    s -= (x * m[x]);
    s += (y * m[x]);
    m[y] += m[x];
    m[x] = 0;
    cout << s << endl;
  }
}
