#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  map<int, int> m;
  int a, b, c;
  int N, Q;
  int all = 0;
  cin >> N;
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    cin >> a;
    m[a]++;
    all += a;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    all = (c - b) * m[b] + all;
    m[c] += m[b];
    m[b] = 0;
    cout << all << endl;
  }
}
