#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  long long sum = 0;
  int a[n];
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  int q, b, c;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    sum -= m[b] * (b - c);
    int x = m[b];
    m[b] = 0;
    m[c] = x;
    cout << sum << "\n";
  }
}
int main(void) {
  int t;
  t = 1;
  while (t--) solve();
}
