#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  int tmp;
  int cnt[100000 + 7] = {};
  int sum = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> tmp;
    sum += tmp;
    cnt[tmp]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int v, k;
    cin >> v >> k;
    cout << sum - (v * cnt[v]) + (k * cnt[v]) << endl;
    sum = sum - (v * cnt[v]) + (k * cnt[v]);
    cnt[k] += cnt[v];
    cnt[v] = 0;
  }
}
