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