#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  map<long long, long long> mp;
  long long a;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a;
    mp[a] += 1;
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < (int)(q); i++) {
    cin >> b >> c;
    mp[c] += mp[b];
    mp[b] = 0;
    long long ans = 0;
    for (auto itr : mp) {
      ans += itr.first * itr.second;
    }
    cout << ans << endl;
  }
}
