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