#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, q;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    long long sum = 0;
    cin >> b >> c;
    int j = 0;
    while (j != n) {
      if (arr[j] == b) arr[j] = c;
      j++;
    }
    for (int j = 0; j < n; ++j) {
      sum += arr[j];
    }
    cout << sum << "\n";
  }
  return 0;
}
