HTML Tags giving wrong answer

#include<iostream>

#include<string.h>
using namespace std;
int main()
{
int t;
char str[1010];
int length;
cin >> t;
bool flag;
for (int i=0;i<=t-1;i++)
{
cin >> str;
flag=0;

    length=strlen(str);

    if( (str[0]!='<') && (str[1]!='/') && (str[length-1]!='>') && (length<=3) )
    {    
        flag=1;
        cout << "Error" << endl;
    }
    
    if(flag==0)
    {
        for(int j=2;j<=length-2;j++)
        {

            if( (str[j]>='0' && str[j]<='9') || (str[j]>='a' && str[j]<='z') )
            {
                flag=0;
            }
            else
            {
                flag=1;
                cout << "Error" <<endl;
                break;
            }
        }
        if(flag==0)
            cout << "Success" <<endl;
    }
}
return 0;

}

In HTMLTAGS can you please help me out … it is giving WA and also when I try to compile without custom input it is showing output Error from line number 36
Please Help

Fails on same test input as this.