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