#include <bits/stdc++.h>
using namespace std;
const int N = 10e5 + 5;
int C[N] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    int s = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      C[a[i]]++;
      s += a[i];
    }
    int q;
    cin >> q;
    int i = 0;
    while (i < q) {
      int b, c;
      cin >> b >> c;
      s = s + (c - b) * C[b];
      C[c] += C[b];
      C[b] = 0;
      cout << s << endl;
      i++;
    }
  }
  return 0;
}
