#include <bits/stdc++.h>
using namespace std;
int a[100010];
int binarySearch(int n, int number[], int find) {
  int low = 0;
  int upper = n - 1;
  while (low <= upper) {
    int mid = (low + upper) / 2;
    if (number[mid] < find)
      low = mid + 1;
    else if (number[mid] > find)
      upper = mid - 1;
    else
      return mid;
  }
  return -1;
}
int main() {
  long long n, q, b, c;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  while (q--) {
    cin >> b >> c;
    long long s = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] == b) a[i] = c;
      s += a[i];
    }
    cout << s << endl;
  }
  return 0;
}
