#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> v;
  int N;
  int A;
  int Q;
  int B, C;
  cin >> N;
  while (N--) {
    cin >> A;
    v.push_back(A);
  }
  cin >> Q;
  while (Q--) {
    int sum = 0;
    cin >> B >> C;
    for (int i = 0; i < v.size(); i++) {
      if (v[i] == B) v[i] = C;
      sum += v[i];
    }
    cout << sum << "\n";
  }
  return 0;
}
