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