#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, int> mii;
  int tmp;
  for (int i = 0; i < (N); ++i) {
    cin >> tmp;
    ++mii[tmp];
  }
  int Q;
  cin >> Q;
  int tmp1, tmp2;
  for (int i = 0; i < (Q); ++i) {
    cin >> tmp1 >> tmp2;
    mii[tmp2] += mii[tmp1];
    mii.erase(tmp1);
    long long ans = 0;
    auto end = mii.end();
    for (auto itr = mii.begin(); itr != end; ++itr) {
      int f = itr->first;
      int s = itr->second;
      ans += f * (long long)s;
    }
    cout << ans << "\n";
  }
  return 0;
}
