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