#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> a(pow(10, 5) + 1, 0);
  int s = 0;
  for (int i = 0; i < (n); ++i) {
    int k;
    cin >> k;
    s += k;
    a[k]++;
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  vector<int> res(q);
  for (int i = 0; i < (q); ++i) {
    cin >> b[i] >> c[i];
    s = s - a[b[i]] * b[i] + a[b[i]] * c[i];
    res[i] = s;
    a[c[i]] += a[b[i]];
    a[b[i]] = 0;
  }
  for (int i = 0; i < (q); ++i) cout << res[i] << endl;
  return 0;
}
