#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
//抄博友程序 完全背包 巧妙 背 没掌握
int dp[10008];//重量i 最少多少钱
int main()
{
int T;
//cin>>T;
scanf("%d",&T);
for(int o=0;o<T;o++)
{
memset(dp,-1,sizeof(dp));
int e,f;
//cin>>e>>f;
scanf("%d%d",&e,&f);
int n;
cin>>n;
dp[0]=0;
for(int k=0;k<n;k++)
{
int w,p;
//cin>>p>>w;
scanf("%d%d",&p,&w);
//for(int tw=w,tp=p;tw<=(f-e);tw=w+tw,tp=tp+p)//成01背包
int tw=w;//抄博友程序
int tp=p;
{
for(int i=0;i<=(f-e);i++)
{
if((i-tw)>=0)
{
if(dp[i]!=-1 && dp[i-tw]!=-1)
{
dp[i]=min(dp[i],dp[i-tw]+tp);
}else if(dp[i]==-1 && dp[i-tw]!=-1)
{
dp[i]=dp[i-tw]+tp;
}
}
}
}
/*
for(int i=0;i<=(f-e);i++)
{
cout<<dp[i]<<" ";
}
cout<<endl;*/
}
if(dp[f-e]==-1)
{
printf("This is impossible.\n");
//cout<<"This is impossible."<<endl;
}else
{
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[f-e]);
//cout<<"The minimum amount of money in the piggy-bank is "<<dp[f-e]<<"."<<endl;
}
}
return 0;
}