#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  int b[10005];
  long long ans = 0;
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[a[i]]++;
    ans += a[i];
  }
  int q, be, af;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> be >> af;
    ans += (af - be) * b[be];
    b[af] += b[be];
    b[be] = 0;
    cout << ans << endl;
  }
  return 0;
}
