#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, k, q, a, b, sum = 0, tmp;
  cin >> n;
  long long arr[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  cin >> q;
  for (i = 1; i <= q; i++) {
    sum = 0;
    cin >> a >> b;
    for (j = 1; j <= n; j++) {
      if (arr[j] == a) {
        arr[j] = b;
      }
      sum += arr[j];
    }
    cout << sum << endl;
  }
}
