#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  map<int, int> m;
  cin >> n;
  int t = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    m[a]++;
    t += a;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int cnt = m[b];
    m[b] = 0;
    m[c] += cnt;
    t += cnt * (c - b);
    cout << t << '\n';
  }
  return 0;
}
