#include<bits/stdc++.h>
usind namespace std;
int main()
{
 long long  int n;
  cin>>n;
  long long int sum=0;
  unordered_map<long long int,long long int>m;
  for(long long int i=0;i<n;i++)
  {
   long long  int temp;
    cin>>temp;
    sum=((long long int)sum+(long long int)temp)%1000000007;
    m[temp]++;
  }
  long long int t;
  cin>>t;
  while(t--)
  {
    long long int a,b;
    cin>>a>>b;
    if(m[a]!=0)
    {
      sum=((long long int)sum-(long long int)(a*m[a])+(long long int)(b*m[a]))%1000000007;
      m[b]=m[b]+m[a];
      m[a]=0;
      cout<<sum<<endl;
    }
    else
    {
      cout<<sum<<endl;
    }
  }
}