#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using PP = pair<int, pair<int, int>>;
using T = tuple<string, int, int>;
const string EMP = " ";
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;
  ull out = 0;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    mp[c] += mp[b];
    mp[b] = 0;
    out = 0;
    for (auto au : mp) {
      out += au.first * au.second;
    }
    cout << out << endl;
  }
  return 0;
}
