WHY IS CODE RUNNING FOR EVERY CUSTOM INPUT CORRECTLY BUT GIVING WRONG ANSWER ON SUBMISSION

My issue

My code

#include <iostream>
using namespace std;

int main() {
    long long t;
    cin>>t;
    while(t--){
        long long n,i;
        long long a[3];
        for(i=0;i<3;i++){
            cin>>a[i];
        }
        cin>>n;
        long long c=0;
        if (n==1){
            cout<<1<<endl;
        }
        else{
            while(n--){
         for(i=0;i<3;i++){
             long long k=0;
              if(a[i]>0){
                 k++;
                 a[i]--;}
          
             c=c+k;
             
            if(n==1){break;}
            
         }}cout<<c<<endl;
    }
}
	return 0;
}

Problem Link: CHBLLNS Problem - CodeChef