#include <bits/stdc++.h>
using namespace std;
void test() {
  int n;
  cin >> n;
  map<int, int> mp;
  int sim = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
    sim += x;
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    sim += (r - l) * mp[l];
    mp[r] += mp[l];
    cout << sim << "\n";
  }
}
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  test();
  return 0;
}
