Help me in solving BFOC problem

My issue

i am not able to solve this problem

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here

}

Problem Link: Buckets Full of Candies Practice Coding Problem - CodeChef

@ishan_2003
here , refer my c++ code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    long long int n,m,l;
	    cin>>n>>m>>l;
	    if(n==0)
	    cout<<m;
	    else
	    {
	        long long int rem=m%(n+l-1);
	        if(rem<l)
	        cout<<rem;
	        else
	        cout<<0;
	    }
	    cout<<endl;
	}

}