#include <bits/stdc++.h>
using namespace std;
int n, a[100005], b[100005], c[100005], q;
long long s = 0;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &b[i], &c[i]);
  }
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        a[j] = c[i];
      }
      s += a[j];
    }
    printf("%d\n", s);
    s = 0;
  }
  return 0;
}
