#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const string alp = "abcdefghijklmnopqrstuvwxyz";
int main() {
  ll N;
  cin >> N;
  map<ll, ll> aMap;
  for (long long i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    if (aMap[a]) {
      aMap[a]++;
    } else {
      aMap[a] = 1;
    }
  }
  map<ll, ll>::iterator it;
  ll Q;
  cin >> Q;
  ll sumAll[Q];
  for (long long i = 0; i < Q; ++i) {
    ll B;
    ll C;
    cin >> B >> C;
    if (aMap[B]) {
      ll cnt = aMap[B];
      if (aMap[C]) {
        aMap[C] = aMap[C] + cnt;
      } else {
        aMap[C] = cnt;
      }
      aMap.erase(B);
    }
    ll sum = 0;
    for (it = aMap.begin(); it != aMap.end(); it++) {
      sum += it->first * it->second;
    }
    sumAll[i] = sum;
  }
  for (long long i = 0; i < Q; ++i) {
    cout << sumAll[i] << endl;
  }
  return 0;
}
