#include<iostream>
#include<cmath>
using namespace std;
typedef struct node
{
int p;
int w;
}Node;
Node a[10001];
int dp[20001];
int main()
{
int text;
cin>>text;
while(text--)
{
int e,f;
cin>>e>>f;
int c = f-e;
int n,ps,ws;
int i,j;
int k = 1;
int h = 2;
cin>>n;
for(i = 1;i <= n;i++)
{
cin>>ps>>ws;
a[k].p = ps;
a[k].w = ws;
while(1)
{
k++;
if(a[k-1].p*2 > c)
break;
else
{
a[k].p = a[k-1].p * 2;
a[k].w = a[k-1].w * 2;
}
}
}
for(i = 0;i <= c;i++)
dp[i] = 1000000;
dp[0] = 0;//
for(i = 1;i < k;i++)
{
for(j = a[i].w ;j <= c;j++)
{
if(dp[j] > dp[j-a[i].w] + a[i].p)
dp[j] = dp[j-a[i].w] + a[i].p;
}
}
if(dp[c] == 1000000)
cout<<"This is impossible."<<endl;
else
cout<<"The minimum amount of money in the piggy-bank is "<<dp[c]<<"."<<endl;
}
return 0;
}