#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  int n;
  scanf("%d", &n);
  
  int* array = malloc(n * sizeof(int));
  int i;
  int count = 0;
  for (i = 0; i < n; ++i)
  {
    scanf("%d", &array[i]);
    count += array[i];
  }
  
  int q, b, c;
  scanf("%d", &q);
  for (i = 0; i < q; ++i)
  {
    scanf("%d %d", &b, &c);
    int j;
    for (j = 0; j < n; ++j)
    {
      if (array[j] == b)
      {
        array[j] = c;
        count += c - b;
      }
    }
    printf("%d\n", count);
  }
  
  free(array);
  
  return 0;
}
