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