#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, q, sum = 0;
  cin >> n;
  long long arr[n + 5];
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
  }
  cin >> q;
  while (q--) {
    sum = 0;
    long long b1, c1;
    cin >> b1 >> c1;
    for (int i = 1; i <= n; ++i) {
      if (arr[i] == b1) {
        arr[i] = c1;
      }
      sum += arr[i];
    }
    cout << sum << endl;
  }
}
int main() {
  int x, t;
  solve();
}
