#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, q;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; i++) cin >> b[i] >> c[i];
  map<int, int> mp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    mp[a[i]]++;
    sum += a[i];
  }
  for (int i = 0; i < q; i++) {
    sum -= b[i] * mp[b[i]];
    sum += c[i] * mp[b[i]];
    mp[c[i]] += mp[b[i]];
    mp[b[i]] = 0;
    cout << sum << endl;
  }
}
