#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, q, oldv = 0, newv = 0, sum = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  cin >> q;
  while (q--) {
    cin >> oldv >> newv;
    long int x = count(a, a + n, oldv);
    replace(a, a + n, oldv, newv);
    sum = sum - (oldv * x) + (newv * x);
    cout << sum << endl;
  }
  return 0;
}
