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