#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
const int INF = 1001001001;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < (n); ++i) {
    int a;
    cin >> a;
    mp[a]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int ans = 0;
    int b, c;
    cin >> b >> c;
    if (mp.count(b)) {
      mp[c] += mp.at(b);
      mp.erase(b);
      for (auto p : mp) {
        ans += p.first * p.second;
      }
      cout << ans << endl;
    } else {
      for (auto p : mp) {
        ans += p.first * p.second;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
