#include <bits/stdc++.h>
using namespace std;
int s[100004], m[100004];
int main() {
  int t, ans = 0;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> s[i];
    m[s[i]]++;
    ans += s[i];
  }
  int r;
  cin >> r;
  for (int i = 0; i < r; i++) {
    int a, b;
    cin >> a >> b;
    int q = b - a;
    ans += m[a] * q;
    m[b] += m[a];
    m[a] = 0;
    cout << ans << endl;
  }
  return 0;
}
