#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, q, sum = 0;
  cin >> n;
  long long arr[n + 5];
  map<long long, long long> mp;
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
    mp[arr[i]]++;
    sum += arr[i];
  }
  cin >> q;
  while (q--) {
    long long b1, c1;
    cin >> b1 >> c1;
    mp[c1] += mp[b1];
    int extra = mp[b1] * (c1 - b1);
    sum += extra;
    cout << sum << endl;
  }
}
int main() {
  int x, t;
  solve();
}
