#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  long long n;
  long long a[100001];
  long long q;
  long long b[100001];
  long long c[100001];
  long long sum[100001];
  for (long long i = 0; i < 100001; i++) {
    sum[i] = 0;
  }
  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];
      }
      sum[j] += a[i];
    }
  }
  for (long long i = 0; i < q; i++) {
    cout << sum[i] << endl;
  }
}
