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