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