#include 

main()
{
	int n[5], p[5], d[5], m[5], replace[5], x[5];
	int i, j;
	for(i=0;i<5;i++)
	{
		scanf("%d%d%d", &n[i], &p[i], &d[i]);
		for(j=0;j=0)&&(m[i]<=4))
		{
			replace[i] = m[i] + d[i];
			replace[i] = replace[i] % 10;
		}
		else
		{
			if(m[i]>d[i])
				replace[i] = m[i]-d[i];
			else
				replace[i] = d[i]-m[i];
			x[i] = replace[i];
			while((x[i]/10)>0)
			{
				x[i] = x[i]/10;
			}
			replace[i] = x[i];
		}
		n[i] = n[i] - m[i] + replace[i];
		for(j=0;j