#include <bits/stdc++.h>
using namespace std;
int arr[100007];
int main() {
  int n;
  cin >> n;
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    arr[i] = x;
  }
  int q;
  cin >> q;
  for (int i = 1, x, y; i <= q; i++) {
    cin >> x >> y;
    int sum = 0;
    for (int j = 1; j <= n; j++) {
      if (arr[j] == x) arr[j] = y;
    }
    for (int z = 1; z <= n; z++) sum += arr[z];
    cout << sum << endl;
  }
}
