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