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