#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i, j, q, x, y, ans = 0;
  cin >> n;
  long long arr[n];
  for (i = 0; i < n; i++) cin >> arr[i];
  cin >> q;
  while (q--) {
    cin >> x >> y;
    long long sum = 0;
    for (i = 0; i < n; i++) {
      if (arr[i] == x) {
        arr[i] = y;
      }
      sum += arr[i];
    }
    cout << sum << '\n';
  }
  return 0;
}
