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