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