#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long n, q;
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << std::setprecision(20);
  cin >> n;
  unordered_map<int, int> a(n + 1);
  for (long long i = 0; i < n; i++) {
    int tmpA;
    cin >> tmpA;
    if (a.count(tmpA) == 0) {
      a[tmpA] = 0;
    }
    a[tmpA]++;
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    a[c] += a[b];
    a.erase(b);
    long long r = 0;
    for (auto &&[key, value] : a) {
      r += key * value;
    }
    cout << r << endl;
  }
}
