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