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