#include <bits/stdc++.h>
using namespace std;
int main() {
  long long m = 0, n;
  cin >> n;
  vector<long long> a(n), x(100010);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x[a[i]]++;
    m += a[i];
  }
  long long q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    long long bb = x[b];
    m += (c - b) * bb;
    x[c] += bb;
    cout << m << endl;
  }
  return 0;
}
