#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(100001);
  ll ans = 0;
  for (int i = 0; i < (n); i++) {
    ll x;
    cin >> x;
    ans += x;
    a[x]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    ans = ans - b * a[b] + c * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << ans << endl;
  }
}
