#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> cnt;
  long long ans = 0;
  for (int i = 0; i < (n); i++) {
    int a;
    cin >> a;
    cnt[a]++;
    ans += a;
  }
  int q;
  cin >> q;
  vector<long long> a;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    cnt[c] += cnt[b];
    ans += c * cnt[b];
    ans -= b * cnt[b];
    cnt[b] = 0;
    a.push_back(ans);
  }
  for (int v : a) {
    cout << v << endl;
  }
  return 0;
}
