#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  map<int, int> a;
  for (int i = 0; i < (n); i++) {
    int tmp;
    cin >> tmp;
    a[tmp]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    a[c] += a[b];
    a[b] = 0;
    int s = 0;
    for (auto p : a) {
      s += p.first * p.second;
    }
    cout << s << endl;
  }
  return 0;
}
