#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, q, n1, n2, sum;
  cin >> n;
  int a[n];
  sum = 0;
  int m[10001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    m[a[i]]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> n1 >> n2;
    sum = sum + (n2 - n1) * m[n1];
    cout << sum << '\n';
    m[n2] = m[n2] + m[n1];
    m[n1] = 0;
  }
  return 0;
}
