#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double INF = 2147483647;
template <class T>
void printv(vector<T> v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    cout << *it << ",";
  }
  cout << endl;
}
template <class T>
void printp(vector<pair<T, T>> v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    cout << (*it).first << "," << (*it).second << endl;
  }
  cout << endl;
}
template <class T>
void printp(map<T, T> v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    cout << (*it).first << "," << (*it).second << endl;
  }
  cout << endl;
}
vector<pair<long long, long long>> prime_factorize(long long N) {
  vector<pair<long long, long long>> res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    long long ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}
int main(void) {
  long long N, Q;
  cin >> N;
  map<long long, long long> A;
  for (long long i = 0; i < (long long)(N); i++) {
    long long tmp;
    cin >> tmp;
    A[tmp]++;
  }
  cin >> Q;
  for (long long i = 0; i < (long long)(Q); i++) {
    long long b, c;
    cin >> b >> c;
    A[c] += A[b];
    A[b] = 0;
    long long s = 0;
    for (auto kv : A) {
      s += kv.first * kv.second;
    }
    cout << s << endl;
  }
  return 0;
}
