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