#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  ;
  for (long long i = 0; i <= n - 1; i++) cin >> a[i];
  ;
  map<int, int> m;
  long long sum = 0;
  for (long long i = 0; i <= n - 1; i++) {
    m[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= m[b] * b;
    sum += m[b] * c;
    int count = m[b];
    m[b] = 0;
    m[c] += count;
    cout << sum << "\n";
    ;
  }
  return 0;
}
