#include <bits/stdc++.h>
using namespace std;
int main(void) {
  cin.exceptions(ios::failbit);
  int n;
  int i = 0;
  int l;
  cin >> n;
  if (n < 1 || n > pow(10, 5)) {
    return 0;
  }
  int* p = (int*)malloc(sizeof(int) * n);
  while (cin >> l) {
    if (l < 1 || l > pow(10, 5)) {
      return 0;
    }
    p[i] = l;
    i++;
    if (i == n) {
      break;
    }
  }
  int q;
  cin >> q;
  if (q < 1 || q > pow(10, 5)) {
    return 0;
  }
  int* total = (int*)malloc(sizeof(int) * q);
  for (i = 0; i < q; i++) {
    int* tmp2 = (int*)malloc(sizeof(int) * 2);
    int j = 0;
    while (cin >> l) {
      if (l < 1 || l > pow(10, 5)) {
        return 0;
      }
      tmp2[j] = l;
      j++;
      if (j == 2) {
        break;
      }
    }
    for (int k = 0; k < n; k++) {
      if (p[k] == tmp2[0]) {
        p[k] = tmp2[1];
      }
      total[i] += p[k];
    }
  }
  for (int i = 0; i < q; i++) {
    cout << total[i] << "\n" << endl;
  }
}
