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