#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  ;
  int n, x, tmp, i, j, cnt;
  long long sum = 0;
  vector<int> v;
  vector<pair<int, int> > v1;
  cin >> n;
  tmp = n;
  while (tmp--) {
    cin >> x;
    sum += x;
    v.push_back(x);
  }
  int arr[100010] = {0};
  sort(v.begin(), v.end());
  for (i = 0; i < n; i++) {
    cnt = 1;
    tmp = v[i];
    for (j = i + 1; j < n; j++) {
      if (v[j] != tmp) {
        break;
      }
      cnt++;
    }
    arr[tmp] = cnt;
    i = j - 1;
  }
  int q, a, b;
  cin >> q;
  while (q--) {
    cin >> a >> b;
    tmp = arr[a];
    sum -= tmp * a;
    sum += tmp * b;
    arr[b] = arr[b] + tmp;
    arr[a] = 0;
    cout << sum << '\n';
  }
  v.clear();
  return 0;
}
