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