#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL);
  unsigned int n = 0;
  scanf("%d", &n);
  vector<int> nums;
  for (unsigned int i = 0; i < n; i++) {
    unsigned int temp;
    scanf("%d", &temp);
    nums.push_back(temp);
  }
  unsigned int n2;
  cin >> n2;
  for (unsigned int i = 0; i < n2; i++) {
    unsigned int a, b;
    scanf("%d %d", &a, &b);
    int sum = 0;
    for (size_t i = 0; i < nums.size(); i++) {
      if (nums[i] == a) nums[i] = b;
      sum += nums[i];
    }
    printf("%d\n", sum);
  }
}
