#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;
int main() {
  int n;
  cin >> n;
  Vec vec(100000, 0);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    vec[x]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    vec[c] += vec[b];
    vec[b] = 0;
    ll s = 0;
    for (int i = 1; i <= 100000; i++) {
      s += i * vec[i];
    }
    cout << s << endl;
  }
}
