#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1e18;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long N, Q;
  cin >> N;
  vector<long long> v(N);
  for (auto &i : v) {
    cin >> i;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    replace(v.begin(), v.end(), B, C);
    cout << accumulate(v.begin(), v.end(), 0) << "\n";
  }
}
