#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void ash() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  ash();
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.emplace_back(x);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    vector<int>::iterator it = a.begin();
    while (it != a.end()) {
      if (*it == x) {
        *it = y;
      }
      it++;
    }
    int sum;
    sum = accumulate(a.begin(), a.end(), 0);
    cout << sum << "\n";
  }
}
