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