#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<long long>;
using vvl = vector<vl>;
int MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
int main(void) {
  int b, c, n, k, q;
  vi a(100100, 0);
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    cin >> k;
    a[k - 1] += 1;
  }
  cin >> q;
  vl d;
  for (int i = 0; i < (int)(q); i++) {
    int ans = 0;
    cin >> b >> c;
    if (a[b - 1]) {
      a[c - 1] += a[b - 1];
      a[b - 1] = 0;
    }
    for (int j = 0; j < (int)(100100); j++) ans += a[j - 1] * j;
    d.push_back(ans);
    ans = 0;
  }
  for (int i = 0; i < (int)((int)d.size()); i++) cout << d[i] << endl;
  return 0;
}
