#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(3);
  int n, b, c, q, value, sum;
  cin >> n;
  memset(a, 0, sizeof(a));
  sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> value;
    a[value]++;
    sum += value;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    sum += (c - b) * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << sum << '\n';
  }
  return 0;
}
