#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int n;
  cin >> n;
  long long int a[n];
  long long int c[100000 + 1] = {0};
  long long int m = 0;
  int ans = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    ans = ans + a[i];
    c[a[i]] = c[a[i]] + 1;
    if (a[i] > m) m = a[i];
  }
  sort(a, a + n);
  long long int q;
  cin >> q;
  while (q--) {
    long long int p, b;
    cin >> p >> b;
    c[b] = c[b] + c[p];
    ans = ans + ((b - p) * c[p]);
    c[p] = 0;
    cout << ans << "\n";
  }
  return 0;
}
