#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int freq[100005] = {0};
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    freq[num]++;
    sum += num;
  }
  int q;
  cin >> q;
  for (int j = 1; j <= q; j++) {
    int ak, bk;
    cin >> ak >> bk;
    sum = sum - (ak * freq[ak]);
    sum = sum + (freq[ak] * bk);
    freq[bk] += freq[ak];
    freq[ak] = 0;
    cout << sum << endl;
  }
  return 0;
}
