#include <bits/stdc++.h>
void get_N(long long int *n) {
  int cnt;
  cnt = scanf("%lld", n);
  return;
}
void get_NK(long long int *n, long long int *k) {
  int cnt;
  cnt = scanf("%lld %lld", n, k);
  return;
}
void get_N1234(long long int *n1, long long int *n2, long long int *n3,
               long long int *n4) {
  int cnt;
  if (n2 == NULL) {
    cnt = scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    cnt = scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    cnt = scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  cnt = scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}
void omit_LF(void) {
  char c;
  int cnt;
  cnt = scanf("%c", &c);
  return;
}
char *get_S(long long int n) {
  char *buf;
  int i;
  int cnt;
  buf = (char *)malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }
  cnt = scanf("%s", buf);
  return buf;
}
char *get_SN(long long int max, long long int *size) {
  char *buf;
  int i;
  int n;
  int cnt;
  buf = (char *)malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }
  cnt = scanf("%s", buf);
  n = strlen(buf);
  *size = n;
  return buf;
}
long long int *get_NSeq(long long int n) {
  long long int *buf;
  long long int i;
  buf = (long long int *)malloc((size_t)(n * sizeof(long long int)));
  for (i = 0; i < n; i++) {
    get_N(&buf[i]);
  }
  return buf;
}
typedef struct _tmp_t {
  long long int a;
  long long int b;
} tmp_t;
int compare_simple(const void *a, const void *b) {
  long long int *x;
  long long int *y;
  x = (long long int *)a;
  y = (long long int *)b;
  if (x > y) return 1;
  if (y < x) return -1;
  return 0;
}
void qsort_simple(long long int *array, int size) {
  qsort(array, size, sizeof(long long int), compare_simple);
}
int compare_a(const void *a, const void *b) {
  tmp_t *x;
  tmp_t *y;
  x = (tmp_t *)a;
  y = (tmp_t *)b;
  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;
  return 0;
}
int compare_b(const void *a, const void *b) {
  tmp_t *x;
  tmp_t *y;
  x = (tmp_t *)a;
  y = (tmp_t *)b;
  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;
  return 0;
}
int compare_x(const void *a, const void *b) {
  long long int *x;
  long long int *y;
  x = (long long int *)a;
  y = (long long int *)b;
  if (*x > *y) return 1;
  if (*x < *y) return -1;
  return 0;
}
void qsort_a(tmp_t *array, int size) {
  qsort(array, size, sizeof(tmp_t), compare_a);
}
void qsort_b(tmp_t *array, int size) {
  qsort(array, size, sizeof(tmp_t), compare_b);
}
int resolve1() {
  long long int R;
  double pi = 3.14159;
  double L;
  get_N(&R);
  L = pi * R * 2;
  printf("%lf", L);
  return 0;
}
int resolve2() {
  long long int N, K;
  long long int *P;
  long long int i;
  long long int total = 0;
  get_NK(&N, &K);
  P = get_NSeq(N);
  qsort(P, N, sizeof(long long int), compare_x);
  for (i = 0; i < K; i++) {
    total += P[i];
  }
  printf("%lld", total);
  return 0;
}
long long int *A;
int main() {
  long long int N, Q, B, C;
  long long int i, j;
  long long int total;
  get_N(&N);
  A = get_NSeq(N);
  get_N(&Q);
  for (i = 0; i < Q; i++) {
    get_NK(&B, &C);
    total = 0;
    for (j = 0; j < N; j++) {
      if (A[j] == B) {
        A[j] = C;
      }
      total += A[j];
    }
    printf("%lld\n", total);
  }
  return 0;
}
