#include <stdio.h>#include <string.h>intL, M, N, find;
intC, lenl, lenr;
structnode{
intl, w;
} left[30], right[30], res[30];
intis_ok(intl, intr)
{
intlsum=0, rsum=0;
inti;
for (i=0; i<l; i++)
{
lsum+= (-left[i].l*2-3) *left[i].w;
}
for (i=0; i<r; i++)
{
rsum+= (right[i].l*2+3) *right[i].w;
}
rsum+=C;
if (lsum>rsum) return0;
lsum=0, rsum=0;
for (i=0; i<l; i++)
{
lsum+= (-left[i].l*2+3) *left[i].w;
}
for (i=0; i<r; i++)
{
rsum+= (right[i].l*2-3) *right[i].w;
}
lsum+=C;
if (rsum>lsum) return0;
return1;
}
voiddfs(intcur, intl, intr)
{
inti;
if (cur==N)
{
for (i=cur-1; i>=0; i--)
printf("%d %d\n", res[i].l, res[i].w);
find=1;
return;
}
for (i=l; i<lenl; i++)
{
if (is_ok(i, r) &&!find)
{
res[cur].l=left[i].l;
res[cur].w=left[i].w;
dfs(cur+1, i+1, r);
}
elsebreak;
}
for (i=r; i<lenr; i++)
{
if (is_ok(l, i) &&!find)
{
res[cur].l=right[i].l;
res[cur].w=right[i].w;
dfs(cur+1, l, i+1);
}
elsebreak;
}
}
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\UVa\\uva_in.txt", "r", stdin);
#endifintcas=1;
inti, j;
intu, v;
structnodetem;
while (scanf("%d%d%d", &L, &M, &N) &&L+M+N)
{
lenl=lenr=0;
for (i=0; i<N; i++)
{
scanf("%d%d", &u, &v);
if (u<0)
{
left[lenl].l=u;
left[lenl++].w=v;
}
else {
right[lenr].l=u;
right[lenr++].w=v;
}
}
for (i=1; i<lenl; i++)
{
for (j=0; j<lenl-i; j++)
{
if ((-left[j].l*2-3) *left[j].w> (-left[j+1].l*2-3) *left[j+1].w)
{
tem=left[j];
left[j] =left[j+1];
left[j+1] =tem;
}
}
}
for (i=1; i<lenr; i++)
{
for (j=0; j<lenr-i; j++)
{
if ((right[j].l*2-3) *right[j].w> (right[j+1].l*2-3) *right[j+1].w)
{
tem=right[j];
right[j] =right[j+1];
right[j+1] =tem;
}
}
}
C=3*M;
printf("Case %d:\n", cas++);
find=0;
dfs(0, 0, 0);
if (!find) printf("Impossible\n");
}
return0;
}