#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  int arr[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int q;
  cin >> q;
  int a, b;
  long long sum;
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    sum = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] == a) {
        arr[i] = b;
      }
      sum += arr[i];
    }
    cout << sum << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int test = 1;
  while (test--) {
    solve();
    cout << "\n";
  }
  return 0;
}
