#include <bits/stdc++.h>
using namespace std;
long long s, n, i, b[100000], a, l, r, q;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    b[a]++;
    s += a;
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> l >> r;
    b[r] += b[l];
    s += b[l] * (r - l);
    b[l] = 0;
    cout << s << endl;
  }
}
