#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, a, q, b, c, s = 0;
  cin >> n;
  vector<int> num;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    num.push_back(a);
  }
  cin >> q;
  for (int j = 0; j < q; ++j) {
    cin >> b >> c;
    s = 0;
    replace(num.begin(), num.end(), b, c);
    for (int i : num) {
      s += i;
    }
    cout << s << "\n";
  }
  return 0;
}
