#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> cnt;
  int n;
  cin >> n;
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    if (!cnt.count(b)) continue;
    sum += (long long)(c - b) * cnt[b];
    cnt[c] += cnt[b];
    cnt.erase(b);
    cout << sum << endl;
  }
}
