#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, i, s = 0;
  cin >> n;
  long long int a[n];
  map<long long int, long long int> mp;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    mp[a[i]]++;
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int x, y;
    cin >> x >> y;
    s -= mp[x] * x;
    s += mp[x] * y;
    mp[y] += mp[x];
    cout << s << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
