#include <bits/stdc++.h>
#define bug(x) cout<<#x<<'='<<x<<'\n'
#define tc() int tc;cin>>tc;for(int _tc=0;_tc<tc;++_tc)
#define up(i,l,r) for(int i=l;i<=r;++i)
#define down(i,r,l) for(int i=r;i>=l;--i)
#define fw(file) freopen(file,"w",stdout)
#define fr(file) freopen(file,"r",stdin)
#define reset(x) memset(x,0,sizeof(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
string s;
int main()
{
ios_base::sync_with_stdio(0);
vector<pair<string, double> > a;
// fr("in.INP");
// fw("out.OUT");
tc()
{
double res=0;
int c, n;
a.clear();
cin >> c >> n;
a.pb({"JD",1.0});
up(i,1,c)
{
double t;
cin >> s >> t;
a.pb({s,t});
}
sort(a.begin(), a.end());
up(i,1,n)
{
double t;
cin >> t >> s;
//bug(t);bug(s);
res += t * (lower_bound(a.begin(), a.end(), mp(s,0.0))->se);
}
cout << fixed << setprecision(6) << res << '\n';
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgYnVnKHgpIGNvdXQ8PCN4PDwnPSc8PHg8PCdcbicKI2RlZmluZSB0YygpIGludCB0YztjaW4+PnRjO2ZvcihpbnQgX3RjPTA7X3RjPHRjOysrX3RjKQojZGVmaW5lIHVwKGksbCxyKSBmb3IoaW50IGk9bDtpPD1yOysraSkKI2RlZmluZSBkb3duKGkscixsKSBmb3IoaW50IGk9cjtpPj1sOy0taSkKI2RlZmluZSBmdyhmaWxlKSBmcmVvcGVuKGZpbGUsInciLHN0ZG91dCkKI2RlZmluZSBmcihmaWxlKSBmcmVvcGVuKGZpbGUsInIiLHN0ZGluKQojZGVmaW5lIHJlc2V0KHgpIG1lbXNldCh4LDAsc2l6ZW9mKHgpKQojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIGZpIGZpcnN0CiNkZ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