#include <bits/stdc++.h>
using namespace std;
int main() {
  unordered_map<int, int> freq;
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int val;
    cin >> val;
    sum += val;
    if (freq.find(val) == freq.end()) freq[val] = 0;
    freq[val]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (freq.find(b) == freq.end()) continue;
    int freqB = freq[b];
    sum -= (freqB * b);
    sum += (freqB * c);
    if (freq.find(c) == freq.end()) freq[c] = 0;
    freq[c] += freqB;
    freq.erase(b);
    cout << sum << endl;
  }
  return 0;
}
