#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q, b, c, sum = 0;
  map<int, int> freq;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    freq[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    if (freq[b] > 0) {
      sum += freq[b] * c - freq[b] * b;
      freq[c] += freq[b];
      freq[b] = 0;
      cout << sum << endl;
    } else {
      cout << sum << endl;
    }
  }
}
