#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(int argc, const char* argv[]) {
  int N;
  cin >> N;
  int A[100000];
  for (int i = 0; i < (N); ++i) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  int B[100000];
  int C[100000];
  for (int i = 0; i < (Q); ++i) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < (Q); ++i) {
    ll res = 0;
    for (int j = 0; j < (N); ++j) {
      if (A[j] == B[i]) {
        A[j] = C[i];
      }
      res += A[j];
    }
    cout << res << endl;
  }
  return 0;
}
