#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
void printVector(const vector<T>& v) {
  for (auto value : v) {
    cout << value << " ";
  }
  cout << endl;
}
int main() {
  ll n, q = 0;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0, i_len = (n); i < i_len; ++i) cin >> a[i];
  cin >> q;
  for (int i = 0, i_len = (q); i < i_len; ++i) {
    ll b, c;
    cin >> b >> c;
    replace(a.begin(), a.end(), b, c);
    ll sum = accumulate(a.begin(), a.end(), 0);
    cout << sum << endl;
  }
  return 0;
}
