#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  long long n, m, a, b;
  cin >> n;
  long long x[n];
  for (long long i = 0; i < n; i++) {
    cin >> x[i];
  }
  cin >> m;
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    long long sum = 0;
    for (long long j = 0; j < n; j++) {
      if (x[j] == a) {
        x[j] = b;
      }
      sum += x[j];
    }
    cout << sum << endl;
  }
}
