#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  vector<int> a;
  vector<pair<int, int>> bc;
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    bc.emplace_back(b, c);
  }
  long long sum;
  for (auto& p : bc) {
    sum = 0;
    for (int& x : a) {
      if (x == p.first) x = p.second;
      sum += x;
    }
    cout << sum << '\n';
  }
  return 0;
}
