#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n;
  int arr[n];
  long long sum = 0;
  unordered_map<int, int> umap;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    umap[arr[i]]++;
  }
  cin >> q;
  int ans[q];
  int x, y;
  for (int i = 0; i < q; i++) {
    cin >> x >> y;
    if (umap.find(x) != umap.end()) {
      sum = sum - (umap[x]) * x + (umap[x]) * y;
      umap[y] += umap[x];
      umap.erase(x);
    }
    ans[i] = sum;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << '\n';
  return 0;
}
