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