#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, a[100000], i, x, y, t, s;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) scanf("%lld", &a[i]);
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld%lld", &x, &y);
    s = 0;
    for (i = 0; i < n; i++) {
      if (a[i] == x) a[i] = y;
      s += a[i];
    }
    printf("%lld\n", s);
  }
}
