Help me in solving SMOL problem

My issue

why it’s getting runtime error? i used the given method

My code

#include <stdio.h>

int main() {
	int t;
	scanf("%d",&t);
	for(int i=0;i<t;i++){
	    int n,k;
	    scanf("%d %d",&n,&k);
	    while(n>=k){
	        n=n-k;
	    }
	    printf("%d\n",n);
	}
	return 0;
}


Learning course: Level up from 1* to 2*
Problem Link: CodeChef: Practical coding for everyone

@smfa
your logic is not right
plzz refer the following solution for better understanding

#include <stdio.h>

int main(void) {
	int t;
	scanf("%d",&t);
	while(t--)
	{
	    int n,k;
	    scanf("%d %d",&n,&k);
	    if (k==0)
	    {
	        printf("%d\n",n);
	    }
	    else
	    {
	        printf("%d\n",n%k);
	    }
    }
	return 0;
}