#include <bits/stdc++.h>
using namespace std;
using ll_t = long long;
using ints_t = vector<int>;
int main() {
  int n;
  cin >> n;
  ints_t ints;
  while (n--) {
    int i;
    cin >> i;
    ints.push_back(i);
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    for (auto &i : ints) {
      if (i == a) {
        i = b;
      }
    }
    ll_t sum = accumulate(ints.begin(), ints.end(), 0);
    cout << sum << "\n";
  }
  return 0;
}
