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