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