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

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