#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a[100001], n, k, sum = 0, i, j, q, p, m;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    cin >> p >> m;
    k = 0;
    for (i = 0; i < n; i++) {
      if (a[i] == p) {
        a[i] = m;
        k++;
      }
    }
    sum = sum + (k * (m - p));
    cout << sum << endl;
  }
  return 0;
}
