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