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