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