#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
const int maxn = 10e5 + 3;
int a[maxn];
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }
  int Q;
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    int sum = 0;
    int B, C;
    scanf("%d%d", &B, &C);
    for (int j = 0; j < N; j++) {
      if (a[j] == B) {
        a[j] = C;
        sum += a[j];
      } else
        sum += a[j];
    }
    cout << sum << endl;
  }
  return 0;
}
