#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unordered_map<int, int> um;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    um[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long int x;
    int b, c;
    cin >> b >> c;
    x = um[b];
    um[c] += x;
    x *= b;
    sum -= x;
    x /= b;
    x *= c;
    sum += x;
    cout << sum << endl;
  }
  return 0;
}
