#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000001;
int main(void) {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  int sum1[q];
  int m = 0;
  for (int i = 0; i < (q); i++) {
    int sum = 0;
    int b, c;
    cin >> b >> c;
    for (int j = 0; j < (n); j++) {
      if (a[j] == b) {
        a[j] = c;
      }
    }
    for (int k = 0; k < (n); k++) {
      sum += a[k];
    }
    sum1[m] = sum;
    m++;
  }
  for (int i = 0; i < (q); i++) {
    cout << sum1[i] << endl;
  }
}
