#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> buc(10101);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    buc[x]++;
    ans += x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    ans += c * buc[b] - buc[b] * b;
    buc[c] += buc[b];
    buc[b] = 0;
    cout << ans << endl;
  }
}
