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