#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, i, m, p, sum = 0, k;
  vector<long long int> s;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    s.push_back(a);
  }
  cin >> k;
  while (k--) {
    cin >> m >> p;
    for (i = 0; i < s.size(); i++) {
      if (s[i] == m) s[i] = p;
    }
    for (i = 0; i < s.size(); i++) sum = sum + s[i];
    cout << sum << endl;
    sum = 0;
  }
}
