#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, t, x, y, k, i, j, p, q;
  cin >> n;
  long long int a[n + 5];
  map<long long int, long long int> mp;
  long long int sum = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  cin >> t;
  while (t--) {
    cin >> x >> y;
    sum += (mp[x] * y - mp[x] * x);
    mp[y] = mp[y] + mp[x];
    cout << sum << endl;
  }
}
