#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  int A[100010] = {};
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    A[a] = A[a] + 1;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int s = 0;
    A[c] = A[c] + A[b];
    A[b] = 0;
    for (int j = 1; j <= 100000; j++) {
      s += j * A[j];
    }
    cout << s << endl;
  }
  return 0;
}
