#include <bits/stdc++.h>
int max1 = -1e9;
using namespace std;
int main(int argc, const char* argv[]) {
  std::ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> lista(10e5 + 10);
  for (int i = 0; i < n; i++) {
    int aux;
    cin >> aux;
    lista[aux] += 1;
    max1 = max(max1, aux);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int aux, aux1;
    cin >> aux >> aux1;
    int tmp;
    tmp = lista[aux];
    lista[aux] = 0;
    lista[aux1] += tmp;
    long long soma = 0;
    for (int j = 0; j <= 10e5 + 5; j++) {
      int val = lista[j] * j;
      soma += val;
    }
    cout << soma << endl;
  }
  return 0;
}
