#include <bits/stdc++.h>
const int SIZE = 1000005;
using namespace std;
int n, q, b, c;
int a[100005];
int ans;
int main() {
  cin >> n;
  ans = 0;
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; i++) {
    cin >> b;
    ans += b;
    a[b]++;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    int j = c - b;
    ans += (j * a[b]);
    a[c] += a[b];
    a[b] = 0;
    cout << ans << endl;
  }
  return 0;
}
