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