#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  long long num;
  int q;
  cin >> q;
  while (q--) {
    num = 0;
    int b, c;
    cin >> b >> c;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) {
        a[i] = c;
      }
    }
    for (int x : a) num += x;
    cout << num << "\n";
  }
  return 0;
}
