#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long a[n], sum = 0;
  int count[100000] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    count[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    if (count[b] > 0) {
      sum = sum - (b * count[b]) + (c * count[b]);
      count[c] += count[b];
    }
    cout << sum << "\n";
  }
}
