#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char nl = '\n';
void sol() {
  int N;
  cin >> N;
  int ar[N];
  for (int i = 0; i < (N); i++) {
    cin >> ar[i];
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int B, C;
    cin >> B >> C;
    long long sum = 0;
    for (int i = 0; i < (N); i++) {
      if (ar[i] == B) {
        ar[i] = C;
      }
      sum += ar[i];
    }
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  while (T--) {
    sol();
  }
  return 0;
}
