whats wrong with the loop it doesnt run for input 1

#include
#include
using namespace std;
int main()
{ int t;
cin>>t;
do
{
int k;
string s;
getline(cin,s);
int w=0,sp=0;
int n=s.length();

		for(int i=0;i<n;i++)
		{
			if(s[i]==' ')
			{k=i+1;
			sp=sp+1;}
		}
	
		for(int i=0;i<n;i++)
{
		if(i==0 || s[i-1]==' ')
		{
			if (islower(s[i]))
			s[i]=toupper(s[i]);
		}
		else
		s[i]=tolower(s[i]);
}
 
		w=sp+1;	
		
		for(int i=0;i<n;i++)
		{if(isupper(s[i]) && w!=1)
		{
			cout<<s[i]<<". ";
		w=w-1;
		}
	if(isupper(s[i]) && w==1)
	{
		for(int j=k;j<n;j++)
		cout<<s[j];
		break;
	}
			
		}
		t=t-1;
	}while(t);
		return 0;
 
}

Please give problem link as well. And if its related to an on going contest, no member will help you. You will have to use search and google and find answers yourself.

//