#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  unordered_map<int, int> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    m[ar[i]]++;
    sum += ar[i];
  }
  int q;
  cin >> q;
  int res = sum;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int cnt = m[a];
    m[a] = 0;
    m[b] += cnt;
    res -= (a) * (cnt);
    res += (b) * (cnt);
    cout << res << endl;
  }
}
