#include <bits/stdc++.h>
using namespace std;
int tong(int a[], int n) {
  int s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
  }
  return s;
}
void chance(int a[], int n, int gt, int k) {
  for (int i = 0; i < n; i++) {
    if (a[i] == gt) a[i] = k;
  }
}
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int t, gt, k;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> gt >> k;
    chance(a, n, gt, k);
    cout << tong(a, n) << endl;
  }
}
