#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O3")
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL);
  int n = 0;
  cin >> n;
  int* nums = new int[n];
  int temp;
  for (size_t i = 0; i < n; i++) {
    cin >> temp;
    nums[i] = temp;
  }
  int n2;
  cin >> n2;
  int a, b;
  int sum = 0;
  for (size_t i = 0; i < n2; i++) {
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      if (nums[i] == a) nums[i] = b;
      sum += nums[i];
    }
    cout << sum << '\n';
    sum = 0;
  }
  return 0;
}
