#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, A, B, C, Q;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; ++i) cin >> v[i];
  cin >> Q;
  while (Q--) {
    cin >> B >> C;
    long long s = 0;
    for (int i = 0; i < N; ++i) {
      if (v[i] == B) v[i] = C;
      s += v[i];
    }
    cout << s << endl;
  }
  return 0;
}
