#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  map<long long, long long> m;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  long long q;
  cin >> q;
  while (q--) {
    long long c = 0;
    long long x, y;
    cin >> x >> y;
    for (int i = 0; i < n; i++) {
      if (a[i] == x) a[i] = y;
      c += a[i];
    }
    cout << c << endl;
  }
  return 0;
}
