#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cin >> k;
  while (k--) {
    int p, q;
    cin >> p >> q;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] == p) a[i] = q;
      sum += a[i];
    }
    cout << sum << endl;
  }
}
