#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, s = 90LL;
  cin >> n;
  long long a[n];
  map<int, int> ck;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    ck[a[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    s -= (long long)ck[b] * b;
    s += (long long)ck[b] * c;
    ck[c] += ck[b];
    ck[b] = 0;
    cout << s << endl;
  }
}
