#include <bits/stdc++.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;
int box[100001];
int main() {
  lll ii, jj, kk;
  vector<int> ret;
  lll n;
  cin >> n;
  vector<lll> a(n);
  lll sum;
  memset(box, 0, sizeof(box));
  sum = 0;
  for (ii = 0; ii < n; ii++) {
    cin >> a[ii];
    box[a[ii]]++;
    sum += a[ii];
  }
  lll q;
  cin >> q;
  lll b, c;
  for (ii = 0; ii < q; ii++) {
    cin >> b >> c;
    sum -= b * box[b];
    box[c] += box[b];
    box[b] = 0;
    sum += c * box[c];
    cout << sum << endl;
  }
  return 0;
}
