#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int maxi = 1e5 + 1;
  long long int counter[maxi];
  long long int a[n];
  long long int s = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    counter[a[i]]++;
    s += a[i];
  }
  long long int q;
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    long long int b, c;
    cin >> b >> c;
    if (counter[b] > 0) {
      long long int t = counter[b];
      counter[b] = 0;
      counter[c] += t;
      s = s + (c - b) * t;
      cout << s << '\n';
    } else {
      cout << s << '\n';
    }
  }
}
