#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyg";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYG";
int main() {
  long long N;
  cin >> N;
  long long a[N];
  long long sum = 0;
  for (int i = 0; i < (int)(N); i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long Q;
  cin >> Q;
  long long b[Q], c[Q];
  for (int i = 0; i < (int)(Q); i++) cin >> b[i] >> c[i];
  for (int j = 0; j < Q; j++) {
    for (int i = 0; i < N; i++) {
      if (a[i] == b[j]) {
        sum += (c[j] - b[j]);
        a[i] = c[i];
      }
    }
    cout << sum << endl;
  }
}
