#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
void print(vector<ll> vec) {
  for (int i = 0; i < ((ll)(vec).size()); i++) {
    if (i) cout << " ";
    cout << vec[i];
  }
  cout << "\n";
}
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  set<ll> now;
  map<ll, ll> cnt;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    now.insert(a[i]);
    cnt[a[i]]++;
  }
  ll q;
  cin >> q;
  ll ans = 0;
  for (auto it : now) {
    ans += cnt[it] * it;
  }
  vector<ll> rec;
  for (int i = 0; i < q; i++) {
    ll b, c;
    cin >> b >> c;
    ans += (c - b) * cnt[b];
    if (cnt[c] != 0)
      cnt[c] += cnt[b];
    else
      cnt[c] = cnt[b];
    rec.push_back(ans);
  }
  for (int i = 0; i < ((ll)(rec).size()); i++) cout << rec[i] << "\n";
  return 0;
}
