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