#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  unsigned long long sum = 0;
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    sum += num;
    m[num]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int a, b;
    cin >> a >> b;
    int cnt = m[a];
    sum -= cnt * a;
    m.erase(a);
    m[b] += cnt;
    sum += cnt * b;
    cout << sum << endl;
  }
  cout << endl;
  return 0;
}
