//also i have checked by breaking the whole program in different funtions.
#include<stdio.h>
#include<stdlib.h>
void fun();
int i,j,k;
char el;
int main()
{
int t;
scanf("%d",&t);// taking the number of inputs
el=getchar();//fflush is not working .. to absorb the /n of previous scanf ..else it's making
the program to malfunction
for(;t>0;t–)
fun(); //calling the fun to get the job done
return 0 ;
}
void fun()
{
int i=0,j=0,k=0;
int fre[24]={0}; // array to store the frequency of elements
int temp;
char ele[24]={0}; // array to store the elements
while(el=getchar())
{
if(!(el>=97&&el<=122))
break; //there may some problem in this condition
for(j=0;j<k;j++) //checking for match in the array
{
if(el==ele[j])// if match found then only incrementing the count
{
fre[j]+=1;
break;
}
}
if(j==k)// if match does not found then including the elemetn in ele[] and making corresponding count
{
ele[k]=el;
fre[k]=1;
k++;
}
}
for(i=0;i<(k-1);i++) // sorting the array of count to get applied the fib logic
{
for(j=(i+1);j<k;j++)
{
if(fre[i]<fre[j])
{
temp=fre[i];
fre[i]=fre[j];
fre[j]=temp;
}
}
}
if(k<3)
printf("Dynamic\n");
else
{
for(i=0;i<(k-2);i++) // checking the condition
{
if(!(fre[i]==fre[i+1]+fre[i+2])) / if match failed the printing not
{
printf("Not\n");
break;
}
}
if(i==(k-2)) // if the aforsaid loop executed totally then the string is dynamic
printf("Dynamic\n");
}
}