#include <bits/stdc++.h>
using namespace std;
void Main() {
  int n, q;
  cin >> n;
  unordered_map<int, long> am;
  for (int i = 0; i < n; i++) {
    long a;
    cin >> a;
    am[a]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    am[c] = am[b] + am[c];
    am.erase(b);
    long sum = 0;
    for (auto j : am) sum += j.first * j.second;
    cout << sum << endl;
  }
}
int main(int argc, char **argv) {
  Main();
  return 0;
}
