#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  map<int, int> ma;
  int msum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    msum += x;
    ma[x]++;
  }
  int t;
  cin >> t;
  while (t--) {
    int v, val;
    cin >> v >> val;
    auto it = ma.find(v);
    ma[val] += ma[v];
    msum += (val - v) * ma[v];
    ma[v] = 0;
    cout << msum << endl;
  }
  return 0;
}
