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