#include <iostream>
using namespace std;
int main()
{
  int N;
  int N1[N] = {};
  int i;
  int j;
  long long sum;
  for (i = 0; i <= N - 1; i++)
  {
    cin >> N1[1];
  }
  int Q;
  cin >> Q;
  int B[Q];
  int C[Q];
  for (i = 0; i <= Q - 1; i++)
  {
    cin >> B[i] >> C[i];
  }
  for (i = 0; i <= Q - 1; i++)
  {
    for (j = 0; j <= N - 1; j++)
    {
      if (N1[j] == B[i])
      {
        N1[j] = C[i];
      }
    }
  }
  for (i = 0; i <= N - 1; i++)
  {
    sum += N1[i];
  }
  cout << sum;
}