#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  long long freq[100001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    freq[a[i]]++;
  }
  long long q;
  cin >> q;
  long long temp = sum;
  long long b, c;
  vector<int> ans;
  while (q--) {
    cin >> b >> c;
    long long pr = b * (freq[b]);
    long long nw = c * (freq[b]);
    temp = temp + (nw - pr);
    freq[c] += freq[b];
    freq[b] = 0;
    ans.push_back(temp);
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
