#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int a[n], d[MX], s{0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    d[a[i]]++;
  }
  int q, b, c;
  cin >> q;
  while (q--) {
    int h{0};
    cin >> b >> c;
    h = d[b];
    d[b] = 0;
    d[c] += h;
    s += h * (c - b);
    cout << s << "\n";
  }
  return 0;
}
