#include <bits/stdc++.h>
using namespace std;
long long inf = 1000000000000001;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q, a, b, c, sum = 0;
  cin >> n;
  int v[n];
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
    mp[v[i]]++;
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int d = mp[b] * (c - b);
    mp[c] += mp[b];
    mp[b] = 0;
    int ans = sum + d;
    sum = ans;
    cout << ans << "\n";
  }
  return 0;
}
