#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 922337203685477;
const long long mininf = -922337203685477;
const long long nax = 1e5 + 5;
int n, q;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n;
  int arr[n + 5];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      if (arr[i] == a) {
        arr[i] = b;
      }
    }
    long long sums = 0;
    for (int i = 0; i < n; i++) {
      sums += arr[i];
    }
    cout << sums << '\n';
  }
}
