#include <bits/stdc++.h>
using namespace std;
int cnt[100001] = {-1};
int main() {
  int n;
  unsigned long long sm = 0;
  cin >> n;
  int arr[n], cnt[100001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    ++cnt[arr[i]];
    sm += arr[i];
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int p, q;
    cin >> p >> q;
    if (cnt[p] != 0) {
      int reduced = cnt[p] * p;
      int add = cnt[p];
      cnt[p] = 0;
      cnt[q] += add;
      int nxt = add * q;
      sm -= reduced;
      sm += nxt;
    }
    cout << sm;
    cout << "\n";
  }
  return 0;
}
