#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, a, q, b, c;
  vector<int> as;
  cin >> n;
  while (n-- && cin >> a) as.push_back(a);
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    for (int k = 0; k < as.size(); k++)
      if (as[k] == b) as[k] = c;
    long long sum = 0;
    for (int j = 0; j < as.size(); j++) sum += as[j];
    cout << sum << '\n';
  }
  return 0;
}
