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