#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, q, sum;
  cin >> n;
  long long arr[100001];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cin >> q;
  long long a, b;
  for (long long i = 0; i < q; i++) {
    sum = 0;
    cin >> a >> b;
    for (long long j = 0; j < n; j++) {
      if (arr[j] == a) arr[j] = b;
      sum += arr[j];
    }
    cout << sum << endl;
  }
  return 0;
}
