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