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