#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long s = 0;
  int n;
  cin >> n;
  vector<int> c(100001);
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    s += t;
    c[t]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    cout << s - c[a] * a + c[a] * b << "\n";
    s += c[a] * b;
    s -= c[a] * a;
    c[b] += c[a];
    c[a] = 0;
  }
  return 0;
}
