#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, q, i, ans = 0;
  int a, b, c, maxnum = 0;
  cin >> n;
  vector<int> arr(100001, 0);
  for (i = 0; i < n; i++) {
    cin >> a;
    arr[a]++;
    if (maxnum < a) maxnum = a;
    ans += a;
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> b >> c;
    ans = ans + arr[b] * (c - b);
    cout << ans;
    arr[c] = arr[c] + arr[b];
    arr[b] = 0;
  }
  return 0;
}
