#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  map<long long, long long> a;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a[x]++;
  }
  long long q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    a[c] += a[b];
    a[b] = 0;
    long long sum = 0;
    for (auto it = a.begin(); it != a.end(); it++) {
      sum += (it->second) * (it->first);
    }
    cout << sum << "\n";
  }
  return 0;
}
