#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n + 1];
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int q;
  cin >> q;
  int ans[q + 1];
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = 1; j <= n; j++) {
      if (a[j] == x) a[j] = y;
    }
    int sum = 0;
    for (int j = 1; j <= n; j++) sum += a[j];
    ans[i] = sum;
  }
  for (int i = 1; i <= q; i++) printf("%d", ans[i]);
  return 0;
}
