#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  int b[q][2];
  for (int i = 0; i < q; i++) {
    cin >> b[i][0] >> b[i][1];
  }
  int sum = accumulate(a, a + n, 0);
  for (int i = 0; i < q; i++) {
    int temp = count(a, a + n, b[i][0]);
    sum = sum - (temp * b[i][0]);
    sum += (temp * b[i][1]);
    replace(a, a + n, b[i][0], b[i][1]);
    cout << sum << endl;
  }
}
