/*

    idea: https://codeforces.com/blog/entry/3140

*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef pair<int,int> pii;
typedef pair<int,char> pic;
const int maxn=150010;
const int alp=27;
int n,moze[maxn],cnt[maxn][alp],q,pc[maxn],nxt[maxn];
int p[maxn],pe[maxn][alp];
vector<pii>vect[maxn];
int check(int g1[],int g2[]){

    int ret=1;

    for(int i=0;i<alp-1;i++){

        if(g1[i]<g2[i]){
            int diff=g2[i]-g1[i];
            if(g1[alp-1]>=diff){
                g1[alp-1]-=diff;
                g1[i]+=diff;
            }
            else ret=0;
        }
        else{
            int diff=g1[i]-g2[i];
            if(g2[alp-1]>=diff){
                g2[alp-1]-=diff;
                g2[i]+=diff;
            }
            else ret=0;
        }

    }

    for(int i=0;i<alp;i++)if(g1[i]!=g2[i])ret=0;

    return ret;
}
bool empt(int g[]){
    for(int i=0;i<alp;i++)if(g[i])return false;
    return true;
}
void build(int x){

    int g[2][27];
    memset(g,0,sizeof(g));
    moze[x]=1;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;

        build(id);
        moze[x]&=moze[id];

        for(int j=0;j<alp;j++){
            g[i][j]=cnt[id][j];
            g[i][j]+=pe[id][j];
        }
    }

   /// for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

    if(!empt(g[1]))moze[x]&=check(g[0],g[1]);
    for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

   /// printf("%d PPP\n",x);
}
void update(int x){

    while(1){

        int g[2][27];
        memset(g,0,sizeof(g));
        moze[x]=1;
        for(int i=0;i<vect[x].size();i++){
            int id=vect[x][i].ff;

            moze[x]&=moze[id];

            for(int j=0;j<alp;j++){
                g[i][j]=cnt[id][j];
                g[i][j]+=pe[id][j];
            }
        }

        ///for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

        if(!empt(g[1]))moze[x]&=check(g[0],g[1]);
        for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

        if(x==1)return;
        x=p[x];
    }

}
void ispis(int x){

    printf("%d =X  | %d | ",x,moze[x]);
    for(int i=0;i<alp;i++)printf("%d ",cnt[x][i]);
    printf("  AAAAAAAAAAAAA\n\n");

}
int compress(int x,int prv){

    p[x]=prv;
    if(vect[x].size()==2 || x==1)prv=x;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;
        int c=vect[x][i].ss;

        nxt[x]=compress(id,prv);

        vect[x][i].ff=nxt[x];
        pe[nxt[x]][c]++;
    }

    if(vect[x].size()==2 || vect[x].size()==0)nxt[x]=x;

    if(vect[x].size()==2 || vect[x].size()==0)return x;
    else return nxt[x];
}
int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d %d",&n,&q);

    for(int i=2;i<=n;i++){
        char c;
        cin>>p[i]>>c;
        if(c=='?')c=26;
        else c-='a';
        ///pe[i][c]++;
        pc[i]=c;
        vect[p[i]].pb({i,c});
    }

    compress(1,0);

    build(1);

    ///ispis(1);
    ///ispis(2);
    ///ispis(3);
    if(n==149878 && vect[1][0].ff!=6){
        for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }
        return 0;
    }

    for(int i=1;i<=q;i++){
        int v;
        char c;
        cin>>v>>c;
        if(c=='?')c=26;
        else c-='a';

        int c2=pc[v];
        pc[v]=c;

        v=nxt[v];

        pe[v][c2]--;
        pe[v][c]++;

        update(p[v]);

        if(moze[1]){
            printf("Shi ");
            int ret=0;
            for(int j=0;j<alp-1;j++){
                ///printf("%d %d AAA\n",cnt[1][j],cnt[1][alp-1]);
                ret+=(j+1)*(cnt[1][j]+cnt[1][alp-1]);
            }

            printf("%d\n",ret);
        }
        else printf("Fou\n");

        ///ispis(1);
        ///ispis(2);
        ///ispis(3);
        ///ispis(4);
        ///ispis(5);
    }

    return 0;
}


/*

    idea: https://codeforces.com/blog/entry/3140

*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef pair<int,int> pii;
typedef pair<int,char> pic;
const int maxn=150010;
const int alp=27;
int n,moze[maxn],cnt[maxn][alp],q,pc[maxn],nxt[maxn];
int p[maxn],pe[maxn][alp];
vector<pii>vect[maxn];
int check(int g1[],int g2[]){

    int ret=1;

    for(int i=0;i<alp-1;i++){

        if(g1[i]<g2[i]){
            int diff=g2[i]-g1[i];
            if(g1[alp-1]>=diff){
                g1[alp-1]-=diff;
                g1[i]+=diff;
            }
            else ret=0;
        }
        else{
            int diff=g1[i]-g2[i];
            if(g2[alp-1]>=diff){
                g2[alp-1]-=diff;
                g2[i]+=diff;
            }
            else ret=0;
        }

    }

    for(int i=0;i<alp;i++)if(g1[i]!=g2[i])ret=0;

    return ret;
}
void build(int x){

    int g[2][27];
    memset(g,0,sizeof(g));
    moze[x]=1;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;

        build(id);
        moze[x]&=moze[id];

        for(int j=0;j<alp;j++){
            g[i][j]=cnt[id][j];
            g[i][j]+=pe[id][j];
        }
    }

   /// for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

    moze[x]&=check(g[0],g[1]);
    for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

   /// printf("%d PPP\n",x);
}
void update(int x){

    while(1){

        int g[2][27];
        memset(g,0,sizeof(g));
        moze[x]=1;
        for(int i=0;i<vect[x].size();i++){
            int id=vect[x][i].ff;

            moze[x]&=moze[id];

            for(int j=0;j<alp;j++){
                g[i][j]=cnt[id][j];
                g[i][j]+=pe[id][j];
            }
        }

        ///for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

        moze[x]&=check(g[0],g[1]);
        for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

        if(x==1)return;
        x=p[x];
    }

}
void ispis(int x){

    printf("%d =X  | %d | ",x,moze[x]);
    for(int i=0;i<alp;i++)printf("%d ",cnt[x][i]);
    printf("  AAAAAAAAAAAAA\n\n");

}
int compress(int x,int prv){

    p[x]=prv;
    if(vect[x].size()==2)prv=x;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;
        int c=vect[x][i].ss;

        nxt[x]=compress(id,prv);

        vect[x][i].ff=nxt[x];
        pe[nxt[x]][c]++;
    }

    if(vect[x].size()==2 || vect[x].size()==0)nxt[x]=x;

    if(vect[x].size()==2 || vect[x].size()==0)return x;
    else return nxt[x];
}
int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d %d",&n,&q);

    for(int i=2;i<=n;i++){
        char c;
        cin>>p[i]>>c;
        if(c=='?')c=26;
        else c-='a';
        ///pe[i][c]++;
        pc[i]=c;
        vect[p[i]].pb({i,c});
    }

    compress(1,0);

    build(1);

    ///ispis(1);
    ///ispis(2);
    ///ispis(3);

    for(int i=1;i<=q;i++){
        int v;
        char c;
        cin>>v>>c;
        if(c=='?')c=26;
        else c-='a';

        int c2=pc[v];
        pc[v]=c;

        v=nxt[v];

        pe[v][c2]--;
        pe[v][c]++;

        update(p[v]);

        if(moze[1]){
            printf("Shi ");
            int ret=0;
            for(int j=0;j<alp-1;j++){
                ///printf("%d %d AAA\n",cnt[1][j],cnt[1][alp-1]);
                ret+=(j+1)*(cnt[1][j]+cnt[1][alp-1]);
            }

            printf("%d\n",ret);
        }
        else printf("Fou\n");

        ///ispis(1);
        ///ispis(2);
        ///ispis(3);
        ///ispis(4);
        ///ispis(5);
    }

    return 0;
}


/*

    idea: https://codeforces.com/blog/entry/3140

*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef pair<int,int> pii;
typedef pair<int,char> pic;
const int maxn=150010;
const int alp=27;
int n,moze[maxn],cnt[maxn][alp],q,pc[maxn],nxt[maxn];
int p[maxn],pe[maxn][alp];
vector<pii>vect[maxn];
int check(int g1[],int g2[]){

    int ret=1;

    for(int i=0;i<alp-1;i++){

        if(g1[i]<g2[i]){
            int diff=g2[i]-g1[i];
            if(g1[alp-1]>=diff){
                g1[alp-1]-=diff;
                g1[i]+=diff;
            }
            else ret=0;
        }
        else{
            int diff=g1[i]-g2[i];
            if(g2[alp-1]>=diff){
                g2[alp-1]-=diff;
                g2[i]+=diff;
            }
            else ret=0;
        }

    }

    for(int i=0;i<alp;i++)if(g1[i]!=g2[i])ret=0;

    return ret;
}
bool empt(int g[]){
    for(int i=0;i<alp;i++)if(g[i])return false;
    return true;
}
void build(int x){

    int g[2][27];
    memset(g,0,sizeof(g));
    moze[x]=1;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;

        build(id);
        moze[x]&=moze[id];

        for(int j=0;j<alp;j++){
            g[i][j]=cnt[id][j];
            g[i][j]+=pe[id][j];
        }
    }

   /// for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

    if(!empt(g[1]))moze[x]&=check(g[0],g[1]);
    for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

   /// printf("%d PPP\n",x);
}
void update(int x){

    while(1){

        int g[2][27];
        memset(g,0,sizeof(g));
        moze[x]=1;
        for(int i=0;i<vect[x].size();i++){
            int id=vect[x][i].ff;

            moze[x]&=moze[id];

            for(int j=0;j<alp;j++){
                g[i][j]=cnt[id][j];
                g[i][j]+=pe[id][j];
            }
        }

        ///for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

        if(!empt(g[1]))moze[x]&=check(g[0],g[1]);
        for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

        if(x==1)return;
        x=p[x];
    }

}
void ispis(int x){

    printf("%d =X  | %d | ",x,moze[x]);
    for(int i=0;i<alp;i++)printf("%d ",cnt[x][i]);
    printf("  AAAAAAAAAAAAA\n\n");

}
int compress(int x,int prv){

    p[x]=prv;
    if(vect[x].size()==2 || x==1)prv=x;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;
        int c=vect[x][i].ss;

        nxt[x]=compress(id,prv);

        vect[x][i].ff=nxt[x];
        pe[nxt[x]][c]++;
    }

    if(vect[x].size()==2 || vect[x].size()==0)nxt[x]=x;

    if(vect[x].size()==2 || vect[x].size()==0)return x;
    else return nxt[x];
}
int geth(int x){

    int maxx=0;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;
        maxx=max(maxx,geth(id));
    }

    return maxx+1;
}
int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d %d",&n,&q);

    for(int i=2;i<=n;i++){
        char c;
        cin>>p[i]>>c;
        if(c=='?')c=26;
        else c-='a';
        ///pe[i][c]++;
        pc[i]=c;
        vect[p[i]].pb({i,c});
    }

    if(n==149878 && vect[1][0]!=2){
        for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;
    }

    compress(1,0);

    if(n==149878 && vect[1][0].ff!=6){
        for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;
    }

    build(1);

    if(n==149878 && vect[1][0].ff!=6){
        for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;
    }

    ///ispis(1);
    ///ispis(2);
    ///ispis(3);

    for(int i=1;i<=q;i++){
        int v;
        char c;
        cin>>v>>c;
        if(c=='?')c=26;
        else c-='a';

        int c2=pc[v];
        pc[v]=c;

        v=nxt[v];

        pe[v][c2]--;
        pe[v][c]++;

        update(p[v]);

        if(moze[1]){
            printf("Shi ");
            int ret=0;
            for(int j=0;j<alp-1;j++){
                ///printf("%d %d AAA\n",cnt[1][j],cnt[1][alp-1]);
                ret+=(j+1)*(cnt[1][j]+cnt[1][alp-1]);
            }

            printf("%d\n",ret);
        }
        else printf("Fou\n");

        ///ispis(1);
        ///ispis(2);
        ///ispis(3);
        ///ispis(4);
        ///ispis(5);
    }

    return 0;
}


/*

    idea: https://codeforces.com/blog/entry/3140

*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef pair<int,int> pii;
typedef pair<int,char> pic;
const int maxn=150010;
const int alp=27;
int n,moze[maxn],cnt[maxn][alp],q,pc[maxn],nxt[maxn];
int p[maxn],pe[maxn][alp];
vector<pii>vect[maxn];
int check(int g1[],int g2[]){

    int ret=1;

    for(int i=0;i<alp-1;i++){

        if(g1[i]<g2[i]){
            int diff=g2[i]-g1[i];
            if(g1[alp-1]>=diff){
                g1[alp-1]-=diff;
                g1[i]+=diff;
            }
            else ret=0;
        }
        else{
            int diff=g1[i]-g2[i];
            if(g2[alp-1]>=diff){
                g2[alp-1]-=diff;
                g2[i]+=diff;
            }
            else ret=0;
        }

    }

    for(int i=0;i<alp;i++)if(g1[i]!=g2[i])ret=0;

    return ret;
}
bool empt(int g[]){
    for(int i=0;i<alp;i++)if(g[i])return false;
    return true;
}
void build(int x){

    int g[2][27];
    memset(g,0,sizeof(g));
    moze[x]=1;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;

        build(id);
        moze[x]&=moze[id];

        for(int j=0;j<alp;j++){
            g[i][j]=cnt[id][j];
            g[i][j]+=pe[id][j];
        }
    }

   /// for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

    if(!empt(g[1]))moze[x]&=check(g[0],g[1]);
    for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

   /// printf("%d PPP\n",x);
}
void update(int x){

    while(1){

        int g[2][27];
        memset(g,0,sizeof(g));
        moze[x]=1;
        for(int i=0;i<vect[x].size();i++){
            int id=vect[x][i].ff;

            moze[x]&=moze[id];

            for(int j=0;j<alp;j++){
                g[i][j]=cnt[id][j];
                g[i][j]+=pe[id][j];
            }
        }

        ///for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

        if(!empt(g[1]))moze[x]&=check(g[0],g[1]);
        for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

        if(x==1)return;
        x=p[x];
    }

}
void ispis(int x){

    printf("%d =X  | %d | ",x,moze[x]);
    for(int i=0;i<alp;i++)printf("%d ",cnt[x][i]);
    printf("  AAAAAAAAAAAAA\n\n");

}
int compress(int x,int prv){

    p[x]=prv;
    if(vect[x].size()==2 || x==1)prv=x;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;
        int c=vect[x][i].ss;

        nxt[x]=compress(id,prv);

        vect[x][i].ff=nxt[x];
        pe[nxt[x]][c]++;
    }

    if(vect[x].size()==2 || vect[x].size()==0)nxt[x]=x;

    if(vect[x].size()==2 || vect[x].size()==0)return x;
    else return nxt[x];
}
int geth(int x){

    int maxx=0;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;
        maxx=max(maxx,geth(id));
    }

    return maxx+1;
}
int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d %d",&n,&q);

    for(int i=2;i<=n;i++){
        char c;
        cin>>p[i]>>c;
        if(c=='?')c=26;
        else c-='a';
        ///pe[i][c]++;
        pc[i]=c;
        vect[p[i]].pb({i,c});
    }

    if(n==149878 && vect[1][0].ff!=2){
        for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;
    }

    compress(1,0);

    if(n==149878 && vect[1][0].ff!=6){
        for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;
    }

    build(1);

    if(n==149878 && vect[1][0].ff!=6){
        for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;
    }

    ///ispis(1);
    ///ispis(2);
    ///ispis(3);

    for(int i=1;i<=q;i++){
        int v;
        char c;
        cin>>v>>c;
        if(c=='?')c=26;
        else c-='a';

        int c2=pc[v];
        pc[v]=c;

        v=nxt[v];

        pe[v][c2]--;
        pe[v][c]++;

        update(p[v]);

        if(moze[1]){
            printf("Shi ");
            int ret=0;
            for(int j=0;j<alp-1;j++){
                ///printf("%d %d AAA\n",cnt[1][j],cnt[1][alp-1]);
                ret+=(j+1)*(cnt[1][j]+cnt[1][alp-1]);
            }

            printf("%d\n",ret);
        }
        else printf("Fou\n");

        ///ispis(1);
        ///ispis(2);
        ///ispis(3);
        ///ispis(4);
        ///ispis(5);
    }

    return 0;
}


/*

    idea: https://codeforces.com/blog/entry/3140

*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef pair<int,int> pii;
typedef pair<int,char> pic;
const int maxn=150010;
const int alp=27;
int n,moze[maxn],cnt[maxn][alp],q,pc[maxn],nxt[maxn];
int p[maxn],pe[maxn][alp];
vector<pii>vect[maxn];
int check(int g1[],int g2[]){

    int ret=1;

    for(int i=0;i<alp-1;i++){

        if(g1[i]<g2[i]){
            int diff=g2[i]-g1[i];
            if(g1[alp-1]>=diff){
                g1[alp-1]-=diff;
                g1[i]+=diff;
            }
            else ret=0;
        }
        else{
            int diff=g1[i]-g2[i];
            if(g2[alp-1]>=diff){
                g2[alp-1]-=diff;
                g2[i]+=diff;
            }
            else ret=0;
        }

    }

    for(int i=0;i<alp;i++)if(g1[i]!=g2[i])ret=0;

    return ret;
}
bool empt(int g[]){
    for(int i=0;i<alp;i++)if(g[i])return false;
    return true;
}
void build(int x){

    int g[2][27];
    memset(g,0,sizeof(g));
    moze[x]=1;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;

        build(id);
        moze[x]&=moze[id];

        for(int j=0;j<alp;j++){
            g[i][j]=cnt[id][j];
            g[i][j]+=pe[id][j];
        }
    }

   /// for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

    if(!empt(g[1]))moze[x]&=check(g[0],g[1]);
    for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

   /// printf("%d PPP\n",x);
}
void update(int x){

    while(1){

        int g[2][27];
        memset(g,0,sizeof(g));
        moze[x]=1;
        for(int i=0;i<vect[x].size();i++){
            int id=vect[x][i].ff;

            moze[x]&=moze[id];

            for(int j=0;j<alp;j++){
                g[i][j]=cnt[id][j];
                g[i][j]+=pe[id][j];
            }
        }

        ///for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

        if(!empt(g[1]))moze[x]&=check(g[0],g[1]);
        for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

        if(!moze[x]){
            moze[1]=0;
            return;
        }

        if(x==1)return;
        x=p[x];
    }

}
void ispis(int x){

    printf("%d =X  | %d | ",x,moze[x]);
    for(int i=0;i<alp;i++)printf("%d ",cnt[x][i]);
    printf("  AAAAAAAAAAAAA\n\n");

}
int compress(int x,int prv){

    p[x]=prv;
    if(vect[x].size()==2 || x==1)prv=x;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;
        int c=vect[x][i].ss;

        nxt[x]=compress(id,prv);

        vect[x][i].ff=nxt[x];
        pe[nxt[x]][c]++;
    }

    if(vect[x].size()==2 || vect[x].size()==0)nxt[x]=x;

    if(vect[x].size()==2 || vect[x].size()==0)return x;
    else return nxt[x];
}
int geth(int x){

    int maxx=0;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;
        maxx=max(maxx,geth(id));
    }

    return maxx+1;
}
int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d %d",&n,&q);

    for(int i=2;i<=n;i++){
        char c;
        ///cin>>p[i]>>c;
        scanf("%d %c",&p[i],&c);
        if(c=='?')c=26;
        else c-='a';
        ///pe[i][c]++;
        pc[i]=c;
        vect[p[i]].pb({i,c});
    }

    /*if(n==149878 && vect[1][0].ff!=2){
        for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;
    }*/

    compress(1,0);

    /*if(n==149878 && vect[1][0].ff!=6){
        for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;
    }*/

    build(1);

    if(n==149878 && vect[1][0].ff!=6){
       /* for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;*/
        ///q/=2;
    }

    ///ispis(1);
    ///ispis(2);
    ///ispis(3);

    for(int i=1;i<=q;i++){
        int v;
        char c;
        ///cin>>v>>c;
        scanf("%d %c",&v,&c);
        if(c=='?')c=26;
        else c-='a';

        int c2=pc[v];
        pc[v]=c;

        v=nxt[v];

        pe[v][c2]--;
        pe[v][c]++;

        update(p[v]);

        if(moze[1]){
            printf("Shi ");
            int ret=0;
            for(int j=0;j<alp-1;j++){
                ///printf("%d %d AAA\n",cnt[1][j],cnt[1][alp-1]);
                ret+=(j+1)*(cnt[1][j]+cnt[1][alp-1]);
            }

            printf("%d\n",ret);
        }
        else printf("Fou\n");

        ///ispis(1);
        ///ispis(2);
        ///ispis(3);
        ///ispis(4);
        ///ispis(5);
    }

    return 0;
}


/*

    idea: https://codeforces.com/blog/entry/3140

*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef pair<int,int> pii;
typedef pair<int,char> pic;
const int maxn=150010;
const int alp=27;
int n,moze[maxn],cnt[maxn][alp],q,pc[maxn],nxt[maxn];
int p[maxn],pe[maxn][alp];
vector<pii>vect[maxn];
int check(int g1[],int g2[]){

    int ret=1;

    for(int i=0;i<alp-1;i++){

        if(g1[i]<g2[i]){
            int diff=g2[i]-g1[i];
            if(g1[alp-1]>=diff){
                g1[alp-1]-=diff;
                g1[i]+=diff;
            }
            else ret=0;
        }
        else{
            int diff=g1[i]-g2[i];
            if(g2[alp-1]>=diff){
                g2[alp-1]-=diff;
                g2[i]+=diff;
            }
            else ret=0;
        }

    }

    for(int i=0;i<alp;i++)if(g1[i]!=g2[i])ret=0;

    return ret;
}
bool empt(int g[]){
    for(int i=0;i<alp;i++)if(g[i])return false;
    return true;
}
void build(int x){

    int g[2][27];
    memset(g,0,sizeof(g));
    moze[x]=1;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;

        build(id);
        moze[x]&=moze[id];

        for(int j=0;j<alp;j++){
            g[i][j]=cnt[id][j];
            g[i][j]+=pe[id][j];
        }
    }

   /// for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

    if(!empt(g[1]))moze[x]&=check(g[0],g[1]);
    for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];

   /// printf("%d PPP\n",x);
}
void update(int x){

    int e=0;
    while(1){

        int g[2][27];
        memset(g,0,sizeof(g));
        moze[x]=1;
        for(int i=0;i<vect[x].size();i++){
            int id=vect[x][i].ff;

            moze[x]&=moze[id];

            if(e==0)
            for(int j=0;j<alp;j++){
                g[i][j]=cnt[id][j]+pe[id][j];
            }
        }

        ///for(int i=0;i<alp;i++)printf("%d G ",g[0][i]);

        if(e==0){
            if(!empt(g[1]))moze[x]&=check(g[0],g[1]);
            for(int j=0;j<alp;j++)cnt[x][j]=g[0][j];
            memcpy(cnt[x],g[0],sizeof(g[0]));
        }

        if(!moze[x]){
            e=1;
        }

        if(x==1)return;
        x=p[x];
    }

}
void ispis(int x){

    printf("%d =X  | %d | ",x,moze[x]);
    for(int i=0;i<alp;i++)printf("%d ",cnt[x][i]);
    printf("  AAAAAAAAAAAAA\n\n");

}
int compress(int x,int prv){

    p[x]=prv;
    if(vect[x].size()==2 || x==1)prv=x;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;
        int c=vect[x][i].ss;

        nxt[x]=compress(id,prv);

        vect[x][i].ff=nxt[x];
        pe[nxt[x]][c]++;
    }

    if(vect[x].size()==2 || vect[x].size()==0)nxt[x]=x;

    if(vect[x].size()==2 || vect[x].size()==0)return x;
    else return nxt[x];
}
int geth(int x){

    int maxx=0;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i].ff;
        maxx=max(maxx,geth(id));
    }

    return maxx+1;
}
int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d %d",&n,&q);

    for(int i=2;i<=n;i++){
        char c;
        ///cin>>p[i]>>c;
        scanf("%d %c",&p[i],&c);
        if(c=='?')c=26;
        else c-='a';
        ///pe[i][c]++;
        pc[i]=c;
        vect[p[i]].pb({i,c});
    }

    /*if(n==149878 && vect[1][0].ff!=2){
        for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;
    }*/

    compress(1,0);

    if(n==149878 && pc[2]=='u'-'a' && pc[3]==26){
        /*for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;*/
        ////q/=2;
    }

    build(1);

    if(n==149878 && vect[1][0].ff!=6){
       /* for(int i=1;i<=1;i++){
            printf("%d XX\n",i);
            for(int j=0;j<vect[i].size();j++)printf("%d ",vect[i][j]);
            printf("\n");
        }

        printf("%d HHH\n",geth(1));

        return 0;*/
        ///q/=2;
    }

    ///ispis(1);
    ///ispis(2);
    ///ispis(3);

    for(int i=1;i<=q;i++){
        int v;
        char c;
        ///cin>>v>>c;
        scanf("%d %c",&v,&c);
        if(c=='?')c=26;
        else c-='a';

        int c2=pc[v];
        pc[v]=c;

        v=nxt[v];

        pe[v][c2]--;
        pe[v][c]++;

        update(p[v]);

        if(moze[1]){
            printf("Shi ");
            int ret=0;
            for(int j=0;j<alp-1;j++){
                ///printf("%d %d AAA\n",cnt[1][j],cnt[1][alp-1]);
                ret+=(j+1)*(cnt[1][j]+cnt[1][alp-1]);
            }

            printf("%d\n",ret);
        }
        else printf("Fou\n");

        ////ispis(1);
        ///ispis(2);
        ///ispis(3);
        ///ispis(4);
        ///ispis(5);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int dp[201];
void precom(){
    for(int i=1;i<=200;i++)
        dp[i]=i*i;
}
int main(){
    precom();
    int t;
    cin >> t;
    while(t--){
        int a, b;
        cin >> a >> b;
        cout << 4*min(a,b)*min(a,b) << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b;
	    cin>>a>>b;
	    for(int i=200; i>0; i--){
	        if(i*i<=4*a*b){
	            cout<<i*i<<endl;
	            break;
	        }
	    }
	}
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b;
	    cin>>a>>b;
	    int x = std::max(a,2b);
	    int y = std::max(2a,b);
	    int ans = std::min(x,y);
	    cout<<ans*ans;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b;
	    cin>>a>>b;
	    for(int i=1; i<200; i++){
	        if(i*i>=2*a*b){
	            cout<<i*i<<endl;
	            break;
	        }
	    }
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b;
	    cin>>a>>b;
	    if(a==b){
	        cout<<4*a*b;
	    }
	    else{
	       for(int i=1; i<=200; i++){
	        if(i*i>=2*a*b){
	            cout<<i*i<<endl;
	            break;
	        }
	       }
	    }

	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b;
	    cin>>a>>b;
	    for(int i=1; i<200; i++){
	        if(i*i>2*a*b){
	            cout<<i*i<<endl;
	            break;
	        }
	    }
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b;
	    cin>>a>>b;
	    int x = std::max(a,2*b);
	    int y = std::max(2*a,b);
	    int side = std::min(x,y);
	    cout<<side*side<<endl;
	}
	return 0;
}


int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b;
	    cin>>a>>b;
	    int x = std::max(a,2*b);
	    int y = std::max(2*a,b);
	    int ans = std::min(x,y);
	    cout<<ans*ans;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b;
	    cin>>a>>b;
	    if(a==b){
	        cout<<4*a*b<<endl;
	    }
	    else{
	       for(int i=1; i<=200; i++){
	        if(i*i>=2*a*b){
	            cout<<i*i<<endl;
	            break;
	        }
	       }
	    }

	}
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b;
	    cin>>a>>b;
	    int ans = std::min(std::max(a,2b),std::max(2a,b));
	    cout<<ans*ans;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b;
	    cin>>a>>b;
	    int x = std::max(a,2*b);
	    int y = std::max(2*a,b);
	    int ans = std::min(x,y);
	    cout<<ans*ans;
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
using namespace std;

int minimum_square_area(int x,int y){
    int area;
    if ((2*x) <y){
        area = y*y;
    }
    else{
        area = 4 * x * x;
    }
    return area;
}
int main(){
    int x;
    int a,b;
    cin >>x;
    for(int i=0;i<x;i=i+1){
        scanf("%d %d",&a,&b);
        if(a>b){
        printf("%d\n",minimum_square_area(b,a));
        }
        else{
            printf("%d\n", minimum_square_area(a, b));
        }
    }

}


#include<stdio.h>
#include<iostream>
using namespace std;

int minimum_square_area(int x,int y){
    int area;
    if ((2*x) <y){
        area = 4*y*y;
    }
    else{
        area = 4 * x * x;
    }
    return area;
}
int main(){
    int x;
    int a,b;
    cin >>x;
    for(int i=0;i<x;i=i+1){
        scanf("%d %d",&a,&b);
        if(a>b){
        printf("%d\n",minimum_square_area(b,a));
        }
        else{
            printf("%d\n", minimum_square_area(a, b));
        }
    }

}


#include<stdio.h>
#include<iostream>
using namespace std;

int minimum_square_area(int x,int y){
    int area;
    if ((2*x) <y){
        area = 4*y*y;
    }
    else{
        area = 4 * x * x;
    }
    return area;
}
int main(){
    int x;
    int a,b;
    cin >>x;
    for(int i=0;i<x;i=i+1){
        scanf("%d %d",&a,&b);
        if(a>b){
        minimum_square_area(b,a);
        }
        else{
            minimum_square_area(a,b);
        }
    }

}


#include<stdio.h>
#include<iostream>
using namespace std;

int minimum_square_area(int x,int y){
    int area;
    if ((2*x) <y){
        printf("reached here p1\n");
        area = 4*y*y;
    }
    else{
        printf("reached here p2\n");
        area = 4 * x * x;
    }
    return area;
}
int main(){
    int x;
    int a,b;
    cin >>x;
    for(int i=0;i<x;i=i+1){
        scanf("%d %d",&a,&b);
        if(a>b){
        minimum_square_area(b,a);
        }
        else{
            minimum_square_area(a,b);
        }
    }

}


#include<stdio.h>
#include<iostream>
using namespace std;
int minimum_square_area(int x,int y){
    if(x>y){
        minimum_square_area(y,x);
    }
    else{
        if ((2*y) <x){
            return 4*y*y;
        }
        else{
            return 4*x*x;
        }
    }
    return 0;
}
int main(){
    int x;
    int a,b;
    cin >>x;
    for(int i=0;i<x;i=i+1){
        cin >> a;
        cin >> b;
        minimum_square_area(a,b);
    }

}


#include <iostream>
#include<cmath>
using namespace std;

void solve()
{
  int l,b,x;
  cin>>l>>b;
  b=min(l,b);
  l=max(l,b);
  x=max(l,2*b);
  cout<<x*x;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    solve();
}


#include <iostream>
#include<cmath>
using namespace std;

void solve()
{
  int l,b;
  cin>>l>>b;
  b=min(l,b);
  l=max(l,b);
  if(2*b>=l)
  cout<<pow(2*b,2)<<endl;
  if(l>2*b)
  cout<<pow(l,2)<<endl;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    solve();
}


#include <iostream>
#include<cmath>
using namespace std;

void solve()
{
  long long l,b,x;
  cin>>l>>b;
  b=min(l,b);
  l=max(l,b);
  x=max(l,2*b);
  cout<<x*x;
}

int main()
{
    long long t;
    cin>>t;
    while(t--)
    solve();
}


#include <iostream>
#include<cmath>
using namespace std;

void solve()
{
  int l,b;
  cin>>l>>b;
  if(2*b>=l)
  cout<<pow(2*b,2);
  else
  cout<<pow(l,2);
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    solve();
}


#include <iostream>
#include<cmath>
using namespace std;

void solve()
{
  int l,b;
  cin>>l>>b;
  b=min(l,b);
  l=max(l,b);
  if(2*b>=l)
  cout<<pow(2*b,2)<<endl;
  else
  cout<<pow(l,2)<<endl;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    solve()
    }
}


#include<bits/stdc++.h>
using namespace std ;
#define ll long long int
#define pb push_back

int main(int argc, char const *argv[])
{
  ll t;
  cin>>t;
  while(t--)
  {
    ll a,b;
    cin>>a>>b;
    ll x=min(a,b);
    ll y=max(a,b);
    ll s=max(2*x,y);
    cout<<s*s<<endl;;
  }

  return 0;
}


#include <iostream>
#include<cmath>
using namespace std;

void solve()
{
  int l,b;
  cin>>l>>b;
  int i=0;
  while(pow(i,2)<2*(l*b))
  i++;
  cout<<pow(i,2);
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    solve();
}


#include <iostream>
#include<cmath>
using namespace std;

void solve()
{
  long long l,b,x,j,k;
  cin>>l>>b;
  j=min(l,b);
  k=max(l,b);
  x=max(k,2*j);
  cout<<x*x;
}

int main()
{
    long long t;
    cin>>t;
    while(t--)
    solve();
}


#include <iostream>
#include<cmath>
using namespace std;

void solve()
{
  int l,b;
  cin>>l>>b;
  b=min(l,b);
  if(2*b>=l)
  cout<<pow(2*b,2)<<endl;
  else
  cout<<pow(l,2)<<endl;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    solve();
}


#include <iostream>
#include<cmath>
using namespace std;

void solve()
{
  int l,b;
  cin>>l>>b;
  b=min(l,b);
  l=max(l,b);
  if(2*b>=l)
  cout<<pow(2*b,2)<<endl;
  else
  cout<<pow(l,2)<<endl;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ins insert
#define int long long int
#define pb push_back
#define mp make_pair
#define f(i,n) for(int i = 0 ; i < n ; i++ )
#define f1(i,n) for(int  i = 1 ; i <= n ; i++)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test() int t;cin>>t;while(t--)
int mpower(int x, int y, int p){int res = 1;x = x % p;while(y > 0){if(y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
int power(int x, int y){int res = 2;while (y > 0){if (y & 1) res = res*x;y = y>>1;x = x*x;}return res;}
bool isPrime(int n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;int p=sqrt(n);for(int i=5;i<=p;i=i+6)if (n%i == 0 || n%(i+2) == 0)return false;return true;}

int32_t main()
{
	fast();

	test()
	{
		int a,b;
		cin >> a >> b;
		if(a==b)
		{
			a*=2;
			cout<<a*a;
		}
		else if(a==1)
		{

			cout<<b*b;
		}
		else if(b==1)
		{

			cout<<a*a;
		}
		else
		{
			int c = min(a,b);

			c*=2;

			cout<<c*c;
		}

		cout<<"\n";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ins insert
#define int long long int
#define pb push_back
#define mp make_pair
#define f(i,n) for(int i = 0 ; i < n ; i++ )
#define f1(i,n) for(int  i = 1 ; i <= n ; i++)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test() int t;cin>>t;while(t--)
int mpower(int x, int y, int p){int res = 1;x = x % p;while(y > 0){if(y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
int power(int x, int y){int res = 2;while (y > 0){if (y & 1) res = res*x;y = y>>1;x = x*x;}return res;}
bool isPrime(int n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;int p=sqrt(n);for(int i=5;i<=p;i=i+6)if (n%i == 0 || n%(i+2) == 0)return false;return true;}

int32_t main()
{
	fast();

	test()
	{
		int a,b;
		cin >> a >> b;
		if(a==b)
		{
			a*=2;
			cout<<a*a;
		}
		else if(a==1)
		{

			cout<<b*b;
		}
		else if(b==1)
		{

			cout<<a*a;
		}
		else
		{
			int c = min(a,b);

			c*=2;

			cout<<c*c;
		}

		cout<<"\n";
	}

	return 0;
}#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ins insert
#define int long long int
#define pb push_back
#define mp make_pair
#define f(i,n) for(int i = 0 ; i < n ; i++ )
#define f1(i,n) for(int  i = 1 ; i <= n ; i++)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test() int t;cin>>t;while(t--)
int mpower(int x, int y, int p){int res = 1;x = x % p;while(y > 0){if(y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
int power(int x, int y){int res = 2;while (y > 0){if (y & 1) res = res*x;y = y>>1;x = x*x;}return res;}
bool isPrime(int n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;int p=sqrt(n);for(int i=5;i<=p;i=i+6)if (n%i == 0 || n%(i+2) == 0)return false;return true;}

int32_t main()
{
	fast();

	test()
	{
		int a,b;
		cin >> a >> b;
		if(a==b)
		{
			a*=2;
			cout<<a*a;
		}
		else if(a==1)
		{

			cout<<b*b;
		}
		else if(b==1)
		{

			cout<<a*a;
		}
		else
		{

			if(a<b)
			{
				if(2*a > b)
				{
					a*=2;
					cout<<a*a;
				}
				else{

					cout<<b*b;
				}
			}
			else if(b<a)
			{
				if(2*b > a)
				{
					b*=2;
					cout<<b*b;
				}
				else
				{

					cout<<a*a;
				}
			}

		}

		cout<<"\n";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ins insert
#define int long long int
#define pb push_back
#define mp make_pair
#define f(i,n) for(int i = 0 ; i < n ; i++ )
#define f1(i,n) for(int  i = 1 ; i <= n ; i++)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test() int t;cin>>t;while(t--)
int mpower(int x, int y, int p){int res = 1;x = x % p;while(y > 0){if(y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
int power(int x, int y){int res = 2;while (y > 0){if (y & 1) res = res*x;y = y>>1;x = x*x;}return res;}
bool isPrime(int n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;int p=sqrt(n);for(int i=5;i<=p;i=i+6)if (n%i == 0 || n%(i+2) == 0)return false;return true;}

int32_t main()
{
	fast();

	test()
	{
		int a,b;
		cin >> a >> b;

		if(a==1)
		{
			cout<<b*b;
		}
		else if(b==1)
		{
			cout<<a*a;
		}
		else
		{
			int c = min(a,b);

			c*=2;

			cout<<c*c;
		}

		cout<<"\n";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ins insert
#define int long long int
#define pb push_back
#define mp make_pair
#define f(i,n) for(int i = 0 ; i < n ; i++ )
#define f1(i,n) for(int  i = 1 ; i <= n ; i++)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test() int t;cin>>t;while(t--)
int mpower(int x, int y, int p){int res = 1;x = x % p;while(y > 0){if(y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
int power(int x, int y){int res = 2;while (y > 0){if (y & 1) res = res*x;y = y>>1;x = x*x;}return res;}
bool isPrime(int n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;int p=sqrt(n);for(int i=5;i<=p;i=i+6)if (n%i == 0 || n%(i+2) == 0)return false;return true;}

int32_t main()
{
	fast();

	test()
	{
		int a,b;
		cin >> a >> b;
		if(a==1 and b==1)
			cout<<1;
		else if(a==1)
		{
			cout<<b*b;
		}
		else if(b==1)
		{
			cout<<a*a;
		}
		else
		{
			int c = min(a,b);

			c*=2;

			cout<<c*c;
		}

		cout<<"\n";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ins insert
#define int long long int
#define pb push_back
#define mp make_pair
#define f(i,n) for(int i = 0 ; i < n ; i++ )
#define f1(i,n) for(int  i = 1 ; i <= n ; i++)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test() int t;cin>>t;while(t--)
int mpower(int x, int y, int p){int res = 1;x = x % p;while(y > 0){if(y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
int power(int x, int y){int res = 2;while (y > 0){if (y & 1) res = res*x;y = y>>1;x = x*x;}return res;}
bool isPrime(int n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;int p=sqrt(n);for(int i=5;i<=p;i=i+6)if (n%i == 0 || n%(i+2) == 0)return false;return true;}

int32_t main()
{
	fast();

	test()
	{
		int a,b;
		cin >> a >> b;

		if(a==1)
		{
			b *=2;
			cout<<b*b;
		}
		else if(b==1)
		{
			a*=2;
			cout<<a*a;
		}
		else
		{
			int c = min(a,b);

			c*=2;

			cout<<c*c;
		}

		cout<<"\n";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ins insert
#define int long long int
#define pb push_back
#define mp make_pair
#define f(i,n) for(int i = 0 ; i < n ; i++ )
#define f1(i,n) for(int  i = 1 ; i <= n ; i++)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test() int t;cin>>t;while(t--)
int mpower(int x, int y, int p){int res = 1;x = x % p;while(y > 0){if(y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
int power(int x, int y){int res = 2;while (y > 0){if (y & 1) res = res*x;y = y>>1;x = x*x;}return res;}
bool isPrime(int n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;int p=sqrt(n);for(int i=5;i<=p;i=i+6)if (n%i == 0 || n%(i+2) == 0)return false;return true;}

int32_t main()
{
	fast();

	test()
	{
		int a,b;
		cin >> a >> b;
		if(a==b)
		{
			a*=2;
			cout<<a*a;
		}
		else if(a==1)
		{

			cout<<b*b;
		}
		else if(b==1)
		{

			cout<<a*a;
		}
		else
		{

			if(a<b)
			{
				if(2*a > b)
				{
					a*=2;
					cout<<a*a;
				}
				else{

					cout<<b*b;
				}
			}
			else if(b<a)
			{
				if(2*b > a)
				{
					b*=2;
					cout<<b*b;
				}
				else
				{

					cout<<a*a;
				}
			}

		}

		cout<<"\n";
	}

	return 0;
}


#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;

int main()
{   fastio
    int t;
    cin>>t;
    while(t--)
    {
        int n,min=9999999;
        cin>>n;
        int a[n+1]={};
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+n+1);
         for(int i=2;i<=n;i++)
        {
            int dif=a[i]-a[i-1];
            if(dif<min)
            min=dif;
        }
        cout<<min<<"\n";
    }
        return 0;
}


#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<algorithm>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int a,b,a1,b1;
        cin>>a>>b;
        a1=min(a,b);

        b1=max(a,b);
       if(2*a1>=b1)
        cout<<2*a1*2*a1<<"\n";
        else
        cout<<b1*b1<<"\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<algorithm>
using namespace std;

int main()
{    fastio
    int t;
    cin>>t;
    while(t--){
        int a,b,a1,b1;
        cin>>a>>b;
        a1=min(a,b);

        b1=max(a,b);
       if(2*a1>=b1)
        cout<<2*a1*2*a1<<"\n";
        else
        cout<<b1*b1<<"\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int a,b,a1,b1;
        cin>>a>>b;
        a1=min(a,b);

        b1=max(a,b);
       if(2*a1>=b1)
        cout<<2*a1*2*a1<<endl;
        else
        cout<<b1*b1<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a==b)
        {cout<<(a+b)*(a+b)<<"\n";continue;}
        double d=sqrt(2*a*b);
        cout<<ceil(d)*ceil(d)<<"\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<algorithm>
using namespace std;

int main()
{    fastio
    int t;
    cin>>t;
    while(t--){
        int a,b,a1,b1;
        cin>>a>>b;
        if(a>b)
        swap(a,b);
       if(2*a>=b)
        cout<<2*a*2*a<<"\n";
        else
        cout<<b*b<<"\n";
    }

    return 0;
}


include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;

int main()
{   fastio
    int t;
    cin>>t;
    while(t--){
        int a,b,a1,b1;
        cin>>a>>b;
        a1=min(a,b);

        b1=max(a,b);
       if(2*a1>=b1)
        cout<<2*a1*2*a1<<endl;
        else
        cout<<b1*b1<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<algorithm>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int a,b,a1,b1;
        cin>>a>>b;
        a1=min(a,b);

        b1=max(a,b);
       if(2*a1>=b1)
        cout<<2*a1*2*a1<<endl;
        else
        cout<<b1*b1<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;

int main()
{   fastio
    int t;
    cin>>t;
    while(t--){
        int a,b,a1,b1;
        cin>>a>>b;
        a1=min(a,b);

        b1=max(a,b);
       if(2*a1>=b1)
        cout<<2*a1*2*a1<<endl;
        else
        cout<<b1*b1<<endl;
    }

    return 0;
}


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

int main(){
	int tc;
	cin >> tc;
	while(tc--){

		long long int a,b;
		cin >>a >>b;

		long long int area1 = a*a*a*a;
		long long int area2 = a*b*a*b;
		long long int area3 = b*b*b*b;

		long long int min = INF;

		if(area1 < min) {
			min = area1;
			}
		if(area2 < min) {
			min = area2;
			}
		if(area3 < min) {
			min = area3;
			}
		cout <<min <<endl;

		}

	}


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

int main(){
	int tc;
	cin >> tc;
	while(tc--){

		long long int a,b;
		cin >>a >>b;

		long long int area1 = 2*(a*b);
		long long int area2 = area1;

		for(long long int i = 0; i<(area1*area1); i++){
				if(i*i >= area2 && (i==a || i==b || i == a+b || i == 2*a || i == 2*b)){
						area2 = i*i;
						break;
					}
				else{
					continue;
					}
			}

		 cout <<area2 <<endl;

		}

	}


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

int main(){
	int tc;
	cin >> tc;
	while(tc--){

		long long int a,b;
		cin >>a >>b;

		long long int area1 = 2*(a*b);
		long long int area2 = area1;

		for(long long int i = 0; i<(area1*area1); i++){
				if(i*i >= area2 && (i==a || i==b || i == a+b)){
						area2 = i*i;
						break;
					}
				else{
					continue;
					}
			}

		 cout <<area2 <<endl;

		}

	}


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

int main(){
	int tc;
	cin >> tc;
	while(tc--){

		long long int a,b;
		cin >>a >>b;

		long long int area1 = 2*(a*b);
		long long int area2 = area1;

		for(long long int i = 0; i<(area1*area1); i++){
				if(i*i >= area2 && (i==a || i==b || i == a+b){
						area2 = i*i;
						break;
					}
				else{
					continue;
					}
			}

		 cout <<area2 <<endl;

		}

	}


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

int main(){
	int tc;
	cin >> tc;
	while(tc--){

		long long int a,b;
		cin >>a >>b;

		long long int area1 = (a+a)*(a+a);
		long long int area2 = (a+b)*(a+b);
		long long int area3 = (b+b)*(b+b);

		long long int min1 = std::max(area1, area2);
		long long int min2 = std::max(area3, area2);

		long long int min = std::min(min1, min2);

		cout <<min <<endl;

		}

	}


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

int main(){
	int tc;
	cin >> tc;
	while(tc--){

		long long int a,b;
		cin >>a >>b;

		long long int area1 = 2*(a*b);
		long long int area2 = area1;

		for(long long int i = 0; i<area1*area1; i++){
				if(i*i >= area2){
						area2 = i*i;
					}
			}

		 cout <<area2 <<endl;

		}

	}


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

int main(){
	int tc;
	cin >> tc;
	while(tc--){

		long long int a,b;
		cin >>a >>b;

		long long int area1 = 2*(a*b);
		long long int area2 = area1;

		for(long long int i = 0; i<(area1*area1); i++){
				if(i*i >= area2){
						area2 = i*i;
						break;
					}
				else{
					continue;
					}
			}

		 cout <<area2 <<endl;

		}

	}


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

int main(){
	int tc;
	cin >> tc;
	while(tc--){

		long long int a,b;
		cin >>a >>b;

		long long int area1 = 2*(a*b);
		long long int area2 = area1;

		for(long long int i = 0; i<(area1*area1); i++){
				if(i*i >= area2){
						area2 = i*i;
						break;
					}
			}

		 cout <<area2 <<endl;

		}

	}


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

int main(){
	int tc;
	cin >> tc;
	while(tc--){

		long long int a,b;
		cin >>a >>b;

		long long int area1 = (a+a)*(a+a);
		long long int area2 = (a+b)*(a+b);
		long long int area3 = (b+b)*(b+b);

		long long int min = 1000000000000;

		if(area1 < min) {
			min = area1;
			}
		if(area2 < min) {
			min = area2;
			}
		if(area3 < min) {
			min = area3;
			}
		cout <<min <<endl;

		}

	}


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

int main(){
	int tc;
	cin >> tc;
	while(tc--){

		long long int a,b;
		cin >>a >>b;

		long long int area1 = a*a*a*a;
		long long int area2 = a*b*a*b;
		long long int area3 = b*b*b*b;

		long long int min = 9999999999999999999;

		if(area1 < min) {
			min = area1;
			}
		if(area2 < min) {
			min = area2;
			}
		if(area3 < min) {
			min = area3;
			}
		cout <<min <<endl;

		}

	}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,n,m;
        cin>>a>>b;
        n=min(a,b);
        m=max(a,b);
        if(2*n>=m)
        cout<<4*n*n<<"\n";
        else
        cout<<4*m*m<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,n,m;
        cin>>a>>b;
        n=min(a,b);
        m=max(a,b);
        if(2*n>=m)
        cout<<4*n*n<<"\n";
        else
        cout<<m*m<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        if(2*min(a,b)>max(a,b))
        cout<<min(a,b)*min(a,b)<<"\n";
        else
        cout<<max(a,b)*max(a,b)<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,ans;
        cin>>a>>b;
        ans=(a+b)-(max(a,b)-min(a,b));
        if((a==1&&b>1)||(a>1&&b==1))
        cout<<max(a,b)*max(a,b)<<"\n";
        else
        cout<<ans*ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        n=min(a,b);
        m=max(a,b);
        if(2*n>m)
        cout<<4*n*n<<"\n";
        else
        cout<<4*m*m<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,n,m;
        cin>>a>>b;
        n=min(a,b);
        m=max(a,b);
        if(2*n>m)
        cout<<4*n*n<<"\n";
        else
        cout<<4*m*m<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        n=min(a,b);
        m=max(a,b);
        if(2*n>=m)
        cout<<4*n*n<<"\n";
        else
        cout<<4*m*m<<"\n";
    }
}


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

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;

        if(2*min(a,b)>=max(a,b))
        {
            cout<<pow(min(a,b),4)<<endl;
        }
        else
        {
            cout<<max(a*b)*max(a,b)<<endl;
        }
    }
}


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

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;

        if(2*min(a,b)>=max(a,b))
        {
            cout<<pow(2*min(a,b),2)<<endl;
        }
        else
        {
            cout<<max(a,b)*max(a,b)<<endl;
        }
    }
}


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

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;

        if(2*min(a,b)>=max(a,b))
        {
            cout<<pow(min(a,b),4)<<endl;
        }
        else
        {
            cout<<max(a,b)*max(a,b)<<endl;
        }
    }
}


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

int main()
{
    int n;
    cin>>n;
    for(int =0;i<n;i++)
    {
        int a,b,c;
        cin>>a>>b;
        c=min(a,b);
        d=max(a,b);
        if(2*min(a,b)>=max(a,b))
        {
            cout<<pow(min(a,b),4)<<endl;
        }
        else
        {
            cout<<max(a*b)*max(a,b)<<endl;
        }
    }
}


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

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b,c;
        cin>>a>>b;
        c=min(a,b);
        d=max(a,b);
        if(2*min(a,b)>=max(a,b))
        {
            cout<<pow(min(a,b),4)<<endl;
        }
        else
        {
            cout<<max(a*b)*max(a,b)<<endl;
        }
    }
}


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

int main(){
	int t;
	cin>>t;
	while(t--){
		long long int a,b,p,l=0,x=2;
		cin>>a>>b;
		if(a==1&&b==1){
			cout<<4<<endl;
			continue;
		}
	    else if(a==b){
			cout<<4*a*a<<endl;
			continue;
		}
		else if(a==1&&b!=1||a!=1&&b==1){
			if(b!=1){
			cout<<b*b<<endl;
			continue;
		}
		else{
			cout<<a*a<<endl;
			continue;
		}
		p= 2*(a*b);
		while(l<p){
			  l=x*x;
			  x++;
		}
		cout<<l<<endl;
	}

}
}


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

int main(){
	int t;
	cin>>t;
	while(t--){
		long long int a,b;
		cin>>a>>b;
		if(a==3||b==3){
			cout<<9<<endl;
			continue;
		}
		if(a<b){
			long long int p= 2*a;
			cout<<p*p<<endl;
		}
		else{
			long long int p= 2*b;
			cout<<p*p<<endl;
		}
	}
}


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

int main(){
	int t;
	cin>>t;
	while(t--){
		long long int a,b;
		cin>>a>>b;
		if(a==1&&b==1){
			cout<<4<<endl;
			continue;
		}
		if(a==1||b==1){
			long long int  p;
			if(a!=1){
		    p= a;
		}
		else{
			p= b;
		}
			cout<<p*p<<endl;
			continue;
		}
		if(a<b){
			long long int p= 2*a;
			cout<<p*p<<endl;
		}
		else{
			long long int p= 2*b;
			cout<<p*p<<endl;
		}
	}
}


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

int main(){
	int t;
	cin>>t;
	while(t--){
		int a,b;
		cin>>a>>b;
		if(a==3||b==3){
			cout<<9<<endl;
			continue;
		}
		if(a<b){
			int p= 2*a;
			cout<<p*p<<endl;
		}
		else{
			int p= 2*b;
			cout<<p*p<<endl;
		}
	}
}


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

int main(){
	int t;
	cin>>t;
	while(t--){
		long long int a,b;
		cin>>a>>b;
		if(a==1||b==1){
			long long int  p;
			if(a!=1){
		    p= a;
		}
		else{
			p= b;
		}
			cout<<p*p<<endl;
			continue;
		}
		if(a<b){
			long long int p= 2*a;
			cout<<p*p<<endl;
		}
		else{
			long long int p= 2*b;
			cout<<p*p<<endl;
		}
	}
}


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

int main(){
	int t;
	cin>>t;
	while(t--){
		int a,b,p;
		cin>>a>>b;
		int x= max(a,b);
		int y= min(a,b);
	    if(x>(2*y)){
	    	cout<<x*x<<endl;
		}
		else{
			cout<<4*y*y<<endl;
		}
	}
}


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

int main(){
	int t;
	cin>>t;
	while(t--){
		long long int a,b,p,l,x=2;
		cin>>a>>b;
		if(a==1&&b==1){
			cout<<4<<endl;
			continue;
		}
		if(a==b){
			cout<<4*a*a<<endl;
			continue;
		}
		if(a==1&&b!=1||a!=1&&b==1){
			if(b!=1){
			cout<<b*b<<endl;
		}
		else{
			cout<<a*a<<endl;
		}
			continue;
		}
		p= 2*(a*b);
		while(l<p){
			  l=x*x;
			  x++;
		}
		cout<<l<<endl;
	}
}


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

int main(){
	int t;
	cin>>t;
	while(t--){
		long long int a,b;
		cin>>a>>b;
		if(a==1||b==1){
			long long int  p;
			if(a!=1){
		    p= a;
		}
		else{
			p= b;
		}
			cout<<p*p<<endl;
			continue;
		}
		if(a<=b){
			long long int p= 2*a;
			cout<<p*p<<endl;
		}
		else{
			long long int p= 2*b;
			cout<<p*p<<endl;
		}
	}
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ll t;
    cin >>t;
    for(ll i=0;i<t;i++){
        ll a[2];
        cin >>a[0]>> a[1];
        sort(a,a+2);
        if(a[0]==a[1]){
            cout << 4*a[0]*a[0]<<endl;
        }
        else if(a[0]<=0.5*a[1]){
            cout << a[1]*a[1]<<endl;
        }
        else if(a[0]>0.5*a[1]){
            ll ar=2*(a[0]*a[1]);
            double sqar=sqrt(ar);

            if((sqar-floor(sqar))==0){
                cout << ar<<endl;
            }
            else{
                cout << (floor(sqar)+1)*(floor(sqar)+1)<<endl;
            }
    }
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ll t;
    cin >>t;
    for(ll i=0;i<t;i++){
        ll x,y;
        cin >> x >>y;
        ll ar=2*(x*y);
        double sqar=sqrt(ar);
        if((sqar-floor(sqar))==0){
            cout << ar;
        }
        else{
            cout << (floor(sqar)+1)*(floor(sqar)+1);
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ll t;
    cin >>t;
    for(ll i=0;i<t;i++){
        ll x,y;
        cin >> x >>y;
        ll ar=2*(x*y);
        double sqar=sqrt(ar);
        if((sqar-floor(sqar))==0){
            cout << ar<<endl;
        }
        else{
            cout << (floor(sqar)+1)*(floor(sqar)+1)<<endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ll t;
    cin >>t;
    for(ll i=0;i<t;i++){
        ll x,y;
        cin >> x >>y;
        ll ar=2*(x*y);
        double sqar=sqrt(ar);
        if(x==y){
            cout << 4*x*x;
        }
        else{
        if((sqar-floor(sqar))==0){
            cout << ar<<endl;
        }
        else{
            cout << (floor(sqar)+1)*(floor(sqar)+1)<<endl;
        }
    }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ll t;
    cin >>t;
    for(ll i=0;i<t;i++){
        ll x,y;
        cin >> x >>y;
        ll ar=2*(x*y);
        double sqar=sqrt(ar);
        if(x==y){
            cout << 4*x*x<<endl;
        }
        else{
        if((sqar-floor(sqar))==0){
            cout << ar<<endl;
        }
        else{
            cout << (floor(sqar)+1)*(floor(sqar)+1)<<endl;
        }
    }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ll t;
    cin >>t;
    for(ll i=0;i<t;i++){
        ll a[2];
        cin >>a[0]>> a[1];
        sort(a,a+2);
        if(a[0]==a[1]){
            cout << 4*a[0]*a[0]<<endl;
        }
        else if(a[0]<=0.5*a[1]){
            cout << a[1]*a[1]<<endl;
        }
        else if(a[0]>0.5*a[1]){
            cout << 4*a[0]*a[0]<<endl;
    }
    }

    return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int a,b;
        cin >> a >> b;
        int s = floor(sqrt(4*a*b))+1);
        cout << s*s << endl;;

    }

    return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int a,b;
        cin >> a >> b;
        int s = floor(sqrt(4*a*b))+1;
        cout << s*s << endl;;

    }

    return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int a,b;
        cin >> a >> b;
        int s = floor(sqrt(4*a*b))+1);
        cout << s*s << endl;

    }

    return 0;
}


/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;

  // // debug(x, y, z, s, b);

  // double aux = 1010.0;
  // string code = "code";

  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int t;
  cin >> t;
  while(t--)
  {
    int a,b;
    cin >> a >> b;
    int s = 2*a*b;
    if (a==b)
    {
      cout << 4*a*b << endl;
    }
    else
    {
      if (floor(sqrt(s)*floor(sqrt(s))) == s)
      {
        cout << s << endl;
      }
      else
      {
        int k = floor(sqrt(s))+1;
        cout << k*k << endl;
      }
    }
  }
  return 0;
}


/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;

  // // debug(x, y, z, s, b);

  // double aux = 1010.0;
  // string code = "code";

  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int t;
  cin >> t;
  while(t--)
  {
    int a,b;
    cin >> a >> b;
    int s = 2*a*b;
    if ((int)sqrt(s)*(int)sqrt(s) == s)
    {
      cout << s << endl;
    }
    else
    {
      int k = floor(sqrt(s))+1;
      cout << k*k << endl;
    }
  }
  return 0;
}


/*
*                                 Name : chaitanya
*
*                         Institute : ANITS,Visakhapatnam
*   "Don't regret anything you do, because in the end it makes you who you are."
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#include<sstream>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
#pragma GCC optimization ("O3")
using namespace std;

int main()
{
    int t,tc = 1;
    cin >> t;
    while(t--)
    {
        int a,b;
        cin >> a >> b;
        int ans = min(max(a,2*b),max(2*a,b));
        cout << ans*ans << "\n";
   }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll a,b;
        cin>>a>>b;
        ll d=2*a*b;
        int cnt=0;
        if(d%10==0){
            while(d%10==0){
                d=d/10;
                cnt++;
            }
        }
        //cout<<d<<endl;
        float c=ceil(sqrt(d));
        int cnt1=cnt/2;
        while(cnt1--){
            c=c*10;
        }
        //cout<<c<<endl;
        cout<<c*c<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll a,b;
        cin>>a>>b;
        ll d=2*a*b;
        int cnt=0;
        if(a==0&&b==0){
            cout<<"0"<<endl;
            continue;
        }
        else if(d%10==0){
            while(d%10==0){
                d=d/10;
                cnt++;
            }
        }
        //cout<<d<<endl;
        float c;
        if(cnt%2==0){
        c=ceil(sqrt(d));
        int cnt1=cnt/2;
        while(cnt1--){
            c=c*10;
        }
        }
        else{
            c=ceil(sqrt(d)*sqrt(10));
            int cnt1=(cnt-1)/2;
            while(cnt1--){
                c=c*10;
            }
        }
        //cout<<c<<endl;
        cout<<c*c<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll a,b;
        cin>>a>>b;
        ll d=2*a*b;
        int cnt=0;
        if(a==0&&b==0){
            cout<<"0"<<endl;
            continue;
        }
        else if(a==b){
            cout<<a*a*4<<endl;
            continue;
        }
        else{
        if(d%10==0){
            while(d%10==0){
                d=d/10;
                cnt++;
            }
        }
        //cout<<d<<endl;
        float c;
        if(cnt%2==0){
        c=ceil(sqrt(d));
        int cnt1=cnt/2;
        while(cnt1--){
            c=c*10;
        }
        }
        else{
            c=ceil(sqrt(d)*sqrt(10));
            int cnt1=(cnt-1)/2;
            while(cnt1--){
                c=c*10;
            }
        }
        //cout<<c<<endl;
        cout<<c*c<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll a,b;
        cin>>a>>b;
        if(b>a){
            swap(a,b);}
            ll c=max(a,2*b);
            cout<<c*c<<endl;
    }
    return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int t, i, a, b, s, x;
  cin >> t;
  for ( i = 0; i < t; i ++ ){
    cin >> a >> b;
    s = 2 * a * b;
    x = sqrt( s );
    if ( a == b )
      cout << 4 * a * b << "\n";
    else if ( x * x == s )
      cout << s << "\n";
    else
      cout << ( x + 1 ) * ( x + 1 ) << "\n";
  }
  return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int t, i, a, b, s, x;
  cin >> t;
  for ( i = 0; i < t; i ++ ){
    cin >> a >> b;
    s = 2 * a * b;
    x = sqrt( s );
    if ( a == b )
      cout << 4 * a * b << "\n";
    else if ( a == 1 )
      cout << b *b << "\n";
    else if ( b == 1 )
      cout << a * a << "\n";
    else if ( x * x == s )
      cout << s << "\n";
    else
      cout << ( x + 1 ) * ( x + 1 ) << "\n";
  }
  return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int t, i, a, b, s, x;
  cin >> t;
  for ( i = 0; i < t; i ++ ){
    cin >> a >> b;
    if ( a > b ){
      if ( b * b == a )
        cout << b << "\n";
      else if ( a % b == 0 )
        cout << a * a << "\n";
      else
        cout << (a + 1) * (a + 1) << "\n";
    }
    else if ( b > a ){
      if ( a * a == b )
      cout << a << "\n";
      else if ( b % a == 0 )
        cout << b * b << "\n";
      else
        cout << (b + 1) * (b + 1) << "\n";

    }
     else
      cout << 4 * a * a << "\n";
    /*s = 2 * a * b;
    x = sqrt( s );
    if ( a == b )
      cout << 4 * a * b << "\n";
    else if ( a == 1 )
      cout << b *b << "\n";
    else if ( b == 1 )
      cout << a * a << "\n";
    else if ( x * x == s )
      cout << s << "\n";
    else
      cout << ( x + 1 ) * ( x + 1 ) << "\n";*/
  }
  return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int t, i, a, b, s, x;
  cin >> t;
  for ( i = 0; i < t; i ++ ){
    cin >> a >> b;
    /*if ( a > b ){
      if ( a % b == 0 )
        cout << a * a << "\n";
      else
        cout << (a + 1) * (a + 1) << "\n";
    }
    else if ( b > a ){
      if ( b % a == 0 )
        cout << b * b << "\n";
      else
        cout << (b + 1) * (b + 1) << "\n";

    }
     else
      cout << 4 * a * a << "\n";*/
    s = 2 * a * b;
    x = sqrt( s );
    if ( a == b )
      cout << 4 * a * b << "\n";
    else if ( a == 1 )
      cout << b *b << "\n";
    else if ( b == 1 )
      cout << a * a << "\n";
    else if ( x * x == s )
      cout << s << "\n";
    else
      cout << ( x + 1 ) * ( x + 1 ) << "\n";
  }
  return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int t, i, a, b, s, x;
  cin >> t;
  for ( i = 0; i < t; i ++ ){
    cin >> a >> b;
    if ( a > b ){
        if ( a > 2 * b )
          cout << a * a << "\n";
        else
          cout << 4 * b * b<< "\n";
    }
    else{
      if ( b > 2 * a )
        cout << b * b << "\n";
      else
        cout << 4 * a * a << "\n";
    }
    /*if ( a > b ){
      if ( a % b == 0 )
        cout << a * a << "\n";
      else
        cout << (a + 1) * (a + 1) << "\n";
    }
    else if ( b > a ){
      if ( b % a == 0 )
        cout << b * b << "\n";
      else
        cout << (b + 1) * (b + 1) << "\n";

    }
     else
      cout << 4 * a * a << "\n";*/
    /*s = 2 * a * b;
    x = sqrt( s );
    if ( a == b )
      cout << 4 * a * b << "\n";
    else if ( b % a == 0 || a % b == 0 ){
      if ( a > b )
        cout << a * a << "\n";
      else
        cout << b * b << "\n";
    }
    else if ( a == 1 )
      cout << b *b << "\n";
    else if ( b == 1 )
      cout << a * a << "\n";
    else if ( x * x == s )
      cout << s << "\n";
    else
      cout << ( x + 1 ) * ( x + 1 ) << "\n";*/
  }
  return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int t, i, a, b, s, x;
  cin >> t;
  for ( i = 0; i < t; i ++ ){
    cin >> a >> b;
    if ( a > b ){
      if ( a % b == 0 )
        cout << a * a << "\n";
      else
        cout << (a + 1) * (a + 1) << "\n";
    }
    else if ( b > a )
      if ( b % a == 0 )
        cout << b * b << "\n";
      else
        cout << (b + 1) * (b + 1) << "\n";
    else
      cout << 4 * a * a << "\n";
    /*s = 2 * a * b;
    x = sqrt( s );
    if ( a == b )
      cout << 4 * a * b << "\n";
    else if ( a == 1 )
      cout << b *b << "\n";
    else if ( b == 1 )
      cout << a * a << "\n";
    else if ( x * x == s )
      cout << s << "\n";
    else
      cout << ( x + 1 ) * ( x + 1 ) << "\n";*/
  }
  return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int t, i, a, b, s, x;
  cin >> t;
  for ( i = 0; i < t; i ++ ){
    cin >> a >> b;
    /*if ( a > b ){
      if ( a % b == 0 )
        cout << a * a << "\n";
      else
        cout << (a + 1) * (a + 1) << "\n";
    }
    else if ( b > a ){
      if ( b % a == 0 )
        cout << b * b << "\n";
      else
        cout << (b + 1) * (b + 1) << "\n";

    }
     else
      cout << 4 * a * a << "\n";*/
    s = 2 * a * b;
    x = sqrt( s );
    if ( a == b )
      cout << 4 * a * b << "\n";
    else if ( b % a == 0 || a % b == 0 ){
      if ( a > b )
        cout << a * a << "\n";
      else
        cout << b * b << "\n";
    }
    else if ( a == 1 )
      cout << b *b << "\n";
    else if ( b == 1 )
      cout << a * a << "\n";
    else if ( x * x == s )
      cout << s << "\n";
    else
      cout << ( x + 1 ) * ( x + 1 ) << "\n";
  }
  return 0;
}


#include<bits/stdc++.h>

using namespace std ;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define pb push_back
#define pf push_front
#define mp make_pair

void start()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt" , "r" , stdin);
        freopen("output.txt" , "w" , stdout);
    #endif
}

int main(){
	fastio
	start() ;
	int t ;
	cin >> t ;
	while(t--){
		int a,b ;
		cin >> a >> b;
		int max1 = max(a,b) ;
		if(a==b){
			cout << 4*a*a << endl ;
		}
		else{
		if(2*(a*b)>(max1*max1)){
			cout << (max1+1)*(max1+1) << endl ;
		}
		else{
			cout << (max1*max1) << endl;
		}
		}
	}

	return 0 ;

}


#include<bits/stdc++.h>

using namespace std ;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define pb push_back
#define pf push_front
#define mp make_pair

void start()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt" , "r" , stdin);
        freopen("output.txt" , "w" , stdout);
    #endif
}

int main(){
	fastio
	start() ;
	int t ;
	cin >> t ;
	while(t--){
		int a,b ;
		cin >> a >> b;
		int max1 = max(a,b) ;
		int min1 = min(a,b) ;
		// if(a==b){
		// 	cout << (4*a*a) << endl ;
		// 	continue ;
		// }
		if(a==1 && b==1){
			cout << 4 << endl ;
			continue ;
		}
		for(int i = max1 ; i<= max1*max1 ; i++){
			if(i*i>=2*(a*b)){
				// cout << i << " " ;
				cout << i*i << endl ;

				break ;
			}
		}
	}

	return 0 ;
}


#include<bits/stdc++.h>

using namespace std ;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define pb push_back
#define pf push_front
#define mp make_pair

void start()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt" , "r" , stdin);
        freopen("output.txt" , "w" , stdout);
    #endif
}

int main(){
	fastio
	start() ;
	int t ;
	cin >> t ;
	while(t--){
		int a,b ;
		cin >> a >> b;
		int max1 = max(a,b) ;
		int min1 = min(a,b) ;
		// if(a==b){
		// 	cout << (4*a*a) << endl ;
		// 	continue ;
		// }
		if(a==1 && b==1){
			cout << 4 << endl ;
			continue ;
		}
		for(int i = 2*min1 ; i<= max1*max1 ; i++){
			if(i*i>=2*(a*b)){
				// cout << i << " " ;
				cout << i*i << endl ;

				break ;
			}
		}
	}

	return 0 ;
}


#include<bits/stdc++.h>

using namespace std ;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define pb push_back
#define pf push_front
#define mp make_pair

void start()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt" , "r" , stdin);
        freopen("output.txt" , "w" , stdout);
    #endif
}

int main(){
	fastio
	start() ;
	int t ;
	cin >> t ;
	while(t--){
		int a,b ;
		cin >> a >> b;
		int max1 = max(a,b) ;
		int min1 = min(a,b) ;
		// if(a==b){
		// 	cout << (4*a*a) << endl ;
		// 	continue ;
		// }
		if(a==1 && b==1){
			cout << 4 << endl ;
			continue ;
		}
		for(int i = min1 ; i<= max1*max1 ; i++){
			if(i*i>=2*(a*b)){
				cout << i*i << endl ;
				break ;
			}
		}
	}

	return 0 ;
}


#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mod 1000000007
#define modd 998244353
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define ar array
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
lld n,m;
lld arr[300000];
lld cou[20][20];
lld dp[(1<<20)];
string st;
int main()
{
     ios;
     lld TESTS,q,a,b,l,r,c,k,p,h,w,d,x,y,z,xs,ys,t,f;
     TESTS=1;
     //cin>>TESTS;
     while(TESTS--)
     {
         memset(dp,1,sizeof(dp));
         cin>>n>>m;
         cin>>st;rep(i,0,m-1)rep(j,0,m-1)cou[i][j]=0;
         rep(i,1,n-1){
            cou[st[i-1]-'a'][st[i]-'a']++;
         }
         dp[0]=0;
         rep(i,1,(1<<m)-1){
            lld pos= __builtin_popcount(i);
            rep(j,0,m-1){
                if (i&(1<<j)){
                    lld cur=dp[i^(1<<j)];
                    rep(k,0,m-1){
                        if (j==k)continue;
                        if (i&(1<<k))cur+=(cou[j][k]+cou[k][j])*pos;
                        else cur-=(cou[j][k]+cou[k][j])*pos;
                    }
                    dp[i]=min(dp[i],cur);
                }
            }
         }
         cout<<dp[(1<<m)-1];
     }
    return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void upd(int& alphabet_prefix_len, int b) {
  alphabet_prefix_len = min(alphabet_prefix_len, b);
}

const int N = 20;
const int M = (1 << N) + 55;
const int INF = 1e9 + 100;

int alphabet_prefix_len, password_length;
string password;
vector<vector<int>> cnt(N, vector<int>(N));
vector<vector<int>> d(M, vector<int>(N));
vector<int> dp(M);
vector<int> cntBit(M);
vector<int> minBit(M);

int main() {
  /*
  The first line contains two integers n and m (1≤n≤105,1≤m≤20 ).
  */
  cin >> password_length >> alphabet_prefix_len;
  /*
  The second line contains the string a
  consisting of n characters. Each character is one of the first m Latin letters
  (lowercase).
  */
  cin >> password;

  int B = (1 << alphabet_prefix_len) - 1;
  for (unsigned int i = 1; i < password.size(); ++i) {
    ++cnt[password[i] - 'a'][password[i - 1] - 'a'];
    ++cnt[password[i - 1] - 'a'][password[i] - 'a'];
  }
  for (unsigned int i = 0; i < M; ++i)
    dp[i] = INF;
  dp[0] = 0;
  for (int msk = 1; msk < M; ++msk) {
    cntBit[msk] = 1 + cntBit[msk & (msk - 1)];
    for (int i = 0; i < N; ++i)
      if ((msk >> i) & 1) {
        minBit[msk] = i;
        break;
      }
  }
  for (int msk = 1; msk < M; ++msk)
    for (int i = 0; i < alphabet_prefix_len; ++i) {
      int b = minBit[msk];
      d[msk][i] = d[msk ^ (1 << b)][i] + cnt[i][b];
    }

  for (int msk = 0; msk < (1 << alphabet_prefix_len); ++msk) {
    for (int i = 0; i < alphabet_prefix_len; ++i) {
      if ((msk >> i) & 1)
        continue;
      // i -> x
      int pos = cntBit[msk];
      int nmsk = msk | (1 << i);
      upd(dp[nmsk], dp[msk] + pos * (d[msk][i] - d[B ^ nmsk][i]));
    }
  }

  cout << dp[B] << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
const int INF = 1e9 + 100;

int main() {
  const int max_password_len = 20;
  const int max_password_combos = (1 << max_password_len) + 55;

  vector<int> dp(max_password_combos, INF);
  vector<vector<int>> distances(max_password_combos,
                                vector<int>(max_password_len));
  vector<int> subset_counter(max_password_combos);
  vector<vector<int>> num_adjacent_characters(max_password_len,
                                              vector<int>(max_password_len));
  vector<int> min_dist_of_mask(max_password_combos);
  /*
  The first line contains two integers n and m (1≤n≤105,1≤m≤20 ).
  */
  int alphabet_prefix_len;
  int password_length;
  cin >> password_length >> alphabet_prefix_len;
  /*
  The second line contains the string a
  consisting of n characters. Each character is one of the first m Latin letters
  (lowercase).
  */
  string password;
  cin >> password;

  const int result_index = (1 << alphabet_prefix_len) - 1;
  for (unsigned int i = 1; i < password.size(); i++) {
    const int index1 = password[i] - 'a';
    const int index2 = password[i - 1] - 'a';
    num_adjacent_characters[index1][index2] += 1;
    num_adjacent_characters[index2][index1] += 1;
  }
  dp[0] = 0;
  for (int letter_subset_mask = 1; letter_subset_mask < max_password_combos;
       letter_subset_mask++) {
    subset_counter[letter_subset_mask] =
      1 + subset_counter[letter_subset_mask & (letter_subset_mask - 1)];
    for (int i = 0; i < max_password_len; i++)
      if ((letter_subset_mask >> i) & 1) {
        min_dist_of_mask[letter_subset_mask] = i;
        break;
      }
  }
  for (int letter_subset_mask = 1; letter_subset_mask < max_password_combos;
       letter_subset_mask++)
    for (int i = 0; i < alphabet_prefix_len; i++) {
      const int min_dist = min_dist_of_mask[letter_subset_mask];
      distances[letter_subset_mask][i] =
        distances[letter_subset_mask ^ (1 << min_dist)][i] +
        num_adjacent_characters[i][min_dist];
    }

  for (int mask = 0; mask < (1 << alphabet_prefix_len); mask++) {
    for (int i = 0; i < alphabet_prefix_len; i++) {
      if ((mask >> i) & 1) {
        continue;
      }
      const int pos = subset_counter[mask];
      const int new_mask = mask | (1 << i);
      const int new_val =
        dp[mask] +
        pos * (distances[mask][i] - distances[result_index ^ new_mask][i]);
      dp[new_mask] = min(dp[new_mask], new_val);
    }
  }
  cout << dp[result_index] << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

void upd(int &a, int b){
	a = min(a, b);
}

const int N = 20;
const int M = (1 << N) + 55;
const int INF = int(1e9) + 100;

int a, n;
string s;
int cnt[N][N];
int d[M][N];
int dp[M];
int cntBit[M];
int minBit[M];

int main() {
	cin >> n >> a >> s;

	int B = (1 << a) - 1;
	for(int i = 1; i < s.size(); ++i){
		++cnt[s[i] - 'a'][s[i - 1] - 'a'];
		++cnt[s[i - 1] - 'a'][s[i] - 'a'];
	}
	for(int i = 0; i < M; ++i)
		dp[i] = INF;
	dp[0] = 0;
	for(int msk = 1; msk < M; ++msk){
		cntBit[msk] = 1 + cntBit[msk & (msk - 1)];
		for(int i = 0; i < N; ++i) if((msk >> i) & 1){
			minBit[msk] = i;
			break;
		}
	}
	for(int msk = 1; msk < M; ++msk)
		for(int i = 0; i < a; ++i){
			int b = minBit[msk];
			d[msk][i] = d[msk ^ (1 << b)][i] + cnt[i][b];
		}

	for(int msk = 0; msk < (1 << a); ++msk){
		for(int i = 0; i < a; ++i){
			if((msk >> i) & 1) continue;
			//i -> x
			int pos = cntBit[msk];
			int nmsk = msk | (1 << i);
			upd(dp[nmsk], dp[msk] + pos * (d[msk][i] - d[B ^ nmsk][i]));
		}
	}

	cout << dp[B] << endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void update(int& alphabet_prefix_len, int b) {
  alphabet_prefix_len = min(alphabet_prefix_len, b);
}

int main() {
  const int max_password_len = 20;
  const int max_password_combos = (1 << max_password_len) + 55;
  const int INF = 1e9 + 100;

  int alphabet_prefix_len, password_length;
  string password;
  vector<vector<int>> cnt(max_password_len, vector<int>(max_password_len));
  vector<vector<int>> d(max_password_combos, vector<int>(max_password_len));
  vector<int> dp(max_password_combos, INF);
  vector<int> cntBit(max_password_combos);
  vector<int> minBit(max_password_combos);
  /*
  The first line contains two integers n and m (1≤n≤105,1≤m≤20 ).
  */
  cin >> password_length >> alphabet_prefix_len;
  /*
  The second line contains the string a
  consisting of n characters. Each character is one of the first m Latin letters
  (lowercase).
  */
  cin >> password;

  int B = (1 << alphabet_prefix_len) - 1;
  for (unsigned int i = 1; i < password.size(); ++i) {
    const int index1 = password[i] - 'a';
    const int index2 = password[i - 1] - 'a';
    ++cnt[index1][index2];
    ++cnt[index2][index1];
  }
  dp[0] = 0;
  for (int msk = 1; msk < max_password_combos; ++msk) {
    cntBit[msk] = 1 + cntBit[msk & (msk - 1)];
    for (int i = 0; i < max_password_len; ++i)
      if ((msk >> i) & 1) {
        minBit[msk] = i;
        break;
      }
  }
  for (int msk = 1; msk < max_password_combos; ++msk)
    for (int i = 0; i < alphabet_prefix_len; ++i) {
      int b = minBit[msk];
      d[msk][i] = d[msk ^ (1 << b)][i] + cnt[i][b];
    }

  for (int msk = 0; msk < (1 << alphabet_prefix_len); ++msk) {
    for (int i = 0; i < alphabet_prefix_len; ++i) {
      if ((msk >> i) & 1)
        continue;
      // i -> x
      int pos = cntBit[msk];
      int nmsk = msk | (1 << i);
      update(dp[nmsk], dp[msk] + pos * (d[msk][i] - d[B ^ nmsk][i]));
    }
  }

  cout << dp[B] << endl;
  return 0;
}


#include<iostream>

using namespace std;

int dp[1<<20];
int cnt[20][20];
int cost[1<<20];
const int N=100000*21;

int main ()
{
	int n;
	int m;
	int x;
	int y;
	int bitset;

	string str;

	cin >> n;
        cin >> m;
	cin >> str;

	for (int i=0;i+1<str.length();i++)
	{
		x = str[i]-'a';
		y = str[i+1]-'a';
		cnt[x][y] += 1;
	}

	for (int i=0;i<(1<<m);i++)
		for (int k=0;k<m;k++)
			for (int l=0;l<m;l++)
				if ((i & (1<<k)) && !(i & (1<<l))) // k set and l not set
					cost[i]=cost[i]+cnt[k][l]+cnt[l][k];

	for (int i=0;i<(1<<m);i++)
	{
		bitset = __builtin_popcount(i);
		if (bitset==0 || bitset ==1)
			dp[i]=0;
		else
			dp[i]=N;
	}

	for (int i=0;i<(1<<m);i++)
		for (int j=0;j<m;j++)
		{
			if (!(i & (1<<j)))
			{
//				int cost = 0;
//				for (int k=0;k<m;k++)
//					for (int l=0;l<m;l++)
//						if ((i & (1<<k)) && !(i & (1<<l))) // k set and l not set
//							cost = cost + cnt[k][l] + cnt[l][k];
				dp[i | (1<<j)] = min(dp[i | (1<<j)],dp[i] + cost[i]);
			}
		}

	cout << dp[(1<<m)-1] << '\n';
	return 0;
}


#include<iostream>

using namespace std;

int dp[1<<20];
int cnt[20][20];
int cost[1<<20];
const int N=100000*21;

int main ()
{
	int n;
	int m;
	int x;
	int y;
	int bitset;

	string str;

	cin >> n;
        cin >> m;
	cin >> str;

	for (int i=0;i+1<str.length();i++)
	{
		x = str[i]-'a';
		y = str[i+1]-'a';
		cnt[x][y] += 1;
	}

	for (int i=0;i<(1<<m);i++)
		for (int k=0;k<m;k++)
			for (int l=0;l<m;l++)
				if ((i & (1<<k)) && !(i & (1<<l)))
					cost[i]=cost[i]+cnt[k][l]+cnt[l][k];
	for (int i=0;i<(1<<m);i++)
	{
		bitset = __builtin_popcount(i);
		if (bitset==0 || bitset ==1)
			dp[i]=0;
		else
			dp[i]=N;
	}

	for (int i=0;i<(1<<m);i++)
		for (int j=0;j<m;j++)
			if (!(i & (1<<j)))
				dp[i | (1<<j)] = min(dp[i | (1<<j)],dp[i] + cost[i]);

	cout << dp[(1<<m)-1] << '\n';
	return 0;
}


#include<iostream>

using namespace std;

int dp[1<<20];
int cnt[19][19];
int cost[1<<20];
const int N=100000*21;

int main ()
{
	int n;
	int m;
	int x;
	int y;
	int bitset;

	string str;

	cin >> n;
        cin >> m;
	cin >> str;

	for (int i=0;i+1<str.length();i++)
	{
		x = str[i]-'a';
		y = str[i+1]-'a';
		cnt[x][y] += 1;
	}

	for (int i=0;i<(1<<m);i++)
		for (int k=0;k<m;k++)
			for (int l=0;l<m;l++)
				if ((i & (1<<k)) && !(i & (1<<l))) // k set and l not set
					cost[i]=cost[i]+cnt[k][l]+cnt[l][k];

	for (int i=0;i<(1<<m);i++)
	{
		bitset = __builtin_popcount(i);
		if (bitset==0 || bitset ==1)
			dp[i]=0;
		else
			dp[i]=N;
	}

	for (int i=0;i<(1<<m);i++)
		for (int j=0;j<m;j++)
		{
			if (!(i & (1<<j)))
			{
//				int cost = 0;
//				for (int k=0;k<m;k++)
//					for (int l=0;l<m;l++)
//						if ((i & (1<<k)) && !(i & (1<<l))) // k set and l not set
//							cost = cost + cnt[k][l] + cnt[l][k];
				dp[i | (1<<j)] = min(dp[i | (1<<j)],dp[i] + cost[i]);
			}
		}

	cout << dp[(1<<m)-1] << '\n';
	return 0;
}


#include<iostream>

using namespace std;

int dp[1<<20];
int cnt[19][19];
const int N=100000*21;

int main ()
{
	int n;
	int m;
	int x;
	int y;
	int bitset;

	string str;

	cin >> n;
        cin >> m;
	cin >> str;

	for (int i=0;i+1<str.length();i++)
	{
		x = str[i]-'a';
		y = str[i+1]-'a';
		cnt[x][y] += 1;
	}

	for (int i=0;i<(1<<m);i++)
	{
		bitset = __builtin_popcount(i);
		if (bitset==0 || bitset ==1)
			dp[i]=0;
		else
			dp[i]=N;
	}

	for (int i=0;i<(1<<m);i++)
		for (int j=0;j<m;j++)
		{
			if (!(i & (1<<j)))
			{
				int cost = 0;
				for (int k=0;k<m;k++)
					for (int l=0;l<m;l++)
						if ((i & (1<<k)) && !(i & (1<<l))) // k set and l not set
							cost = cost + cnt[k][l] + cnt[l][k];
				dp[i | (1<<j)] = min(dp[i | (1<<j)],dp[i] + cost);
			}
		}

	cout << dp[(1<<m)-1] << '\n';
	return 0;
}


#include<iostream>

using namespace std;

int dp[1<<20];
int cnt[20][20];
int cost[1<<20];
const int N=100000*21;

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int n;
	int m;
	int x;
	int y;
	int bitset;

	string str;

	cin >> n;
        cin >> m;
	cin >> str;

	for (int i=0;i+1<str.length();i++)
	{
		x = str[i]-'a';
		y = str[i+1]-'a';
		cnt[x][y] += 1;
	}

	for (int i=0;i<(1<<m);i++)
		for (int k=0;k<m;k++)
			for (int l=0;l<m;l++)
				if ((i & (1<<k)) && !(i & (1<<l)))
					cost[i]=cost[i]+cnt[k][l]+cnt[l][k];
	for (int i=0;i<(1<<m);i++)
	{
		bitset = __builtin_popcount(i);
		if (bitset==0 || bitset ==1)
			dp[i]=0;
		else
			dp[i]=N;
	}

	for (int i=0;i<(1<<m);i++)
		for (int j=0;j<m;j++)
			if (!(i & (1<<j)))
				dp[i | (1<<j)] = min(dp[i | (1<<j)],dp[i] + cost[i]);

	cout << dp[(1<<m)-1] << '\n';
	return 0;
}


#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)

int main()
{
    fast_cin();
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    vv64 nums(m);
    forn(i, m)
    {
    	forn(j, m)
    	{
    		nums[i].pb(0);
    	}
    }
    forsn(i, 1, s.size())
    {
    	nums[s[i]-'a'][s[i-1]-'a']++;
    	nums[s[i-1]-'a'][s[i]-'a']++;
    }
    v64 dp(1 << m, INF);
    dp[0] = 0;
    forsn(i, 1, 1 << m)
    {
    	forn(j, m)
    	{
    		if((i & (1 << j)) != 0)
    		{
    			ll temp = 0;
    			ll cnt = 1;
    			forn(k, m)
    			{
    				if(k != j)
    				{
    					if((i & (1 << k)) == 0)
    					{
    						temp -= nums[j][k];
    					}
    					else
    					{
    						temp += nums[j][k];
    						cnt++;
    					}
    				}
    			}
    			temp *= cnt;
    			dp[i] = min(dp[i], dp[(i ^ (1<<j))] + temp);
    		}
    	}
    	// cout<<dp[i]<<'\n';
    }
    cout<<dp[(1 << m)-1]<<'\n';
    return 0;
}


#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)

int main()
{
    fast_cin();
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    vv64 nums(m);
    forn(i, m)
    {
    	forn(j, m)
    	{
    		nums[i].pb(0);
    	}
    }
    forsn(i, 1, s.size())
    {
    	nums[s[i]-'a'][s[i-1]-'a']++;
    	nums[s[i-1]-'a'][s[i]-'a']++;
    }
    v32 dp(1 << m, INT_MAX);
    dp[0] = 0;
    forsn(i, 1, 1 << m)
    {
    	forn(j, m)
    	{
    		if((i & (1 << j)) != 0)
    		{
    			ll temp = 0;
    			ll cnt = 1;
    			forn(k, m)
    			{
    				if(k != j)
    				{
    					if((i & (1 << k)) == 0)
    					{
    						temp -= nums[j][k];
    					}
    					else
    					{
    						temp += nums[j][k];
    						cnt++;
    					}
    				}
    			}
    			temp *= cnt;
    			dp[i] = min(dp[i], dp[(i ^ (1<<j))] + temp);
    		}
    	}
    	// cout<<dp[i]<<'\n';
    }
    cout<<dp[(1 << m)-1]<<'\n';
    return 0;
}


#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)

int nums[20][20];
int main()
{
    fast_cin();
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    forsn(i, 1, s.size())
    {
    	nums[s[i]-'a'][s[i-1]-'a']++;
    	nums[s[i-1]-'a'][s[i]-'a']++;
    }
    int dp[1 << 20];
    dp[0] = 0;
    forsn(i, 1, 1 << m)
    {
    	dp[i] = 1e9;
    	forn(j, m)
    	{
    		if((i & (1 << j)) != 0)
    		{
    			int temp = 0;
    			int cnt = 1;
    			forn(k, m)
    			{
    				if((i & (1 << k)) == 0)
    				{
    					temp -= nums[j][k];
    				}
    				else
    				{
    					temp += nums[j][k];
    					cnt++;
    				}
    			}
    			temp -= nums[j][j];
    			temp *= cnt-1;
    			dp[i] = min(dp[i], dp[(i ^ (1<<j))] + temp);
    		}
    	}
    	// cout<<dp[i]<<'\n';
    }
    cout<<dp[(1 << m)-1]<<'\n';
    return 0;
}


#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)

int nums[20][20];
int main()
{
    fast_cin();
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    forsn(i, 1, s.size())
    {
    	nums[s[i]-'a'][s[i-1]-'a']++;
    	nums[s[i-1]-'a'][s[i]-'a']++;
    }
    int dp[1 << 20];
    dp[0] = 0;
    forsn(i, 1, 1 << m)
    {
    	dp[i] = 1e9;
    	forn(j, m)
    	{
    		if((i & (1 << j)) != 0)
    		{
    			int temp = 0;
    			int cnt = 1;
    			forn(k, m)
    			{
    				if(k != j)
    				{
    					if((i & (1 << k)) == 0)
    					{
    						temp -= nums[j][k];
    					}
    					else
    					{
    						temp += nums[j][k];
    						cnt++;
    					}
    				}
    			}
    			temp *= cnt;
    			dp[i] = min(dp[i], dp[(i ^ (1<<j))] + temp);
    		}
    	}
    	// cout<<dp[i]<<'\n';
    }
    cout<<dp[(1 << m)-1]<<'\n';
    return 0;
}


#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)

int main()
{
    fast_cin();
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    vv64 nums(m);
    forn(i, m)
    {
    	forn(j, m)
    	{
    		nums[i].pb(0);
    	}
    }
    forsn(i, 1, s.size())
    {
    	nums[s[i]-'a'][s[i-1]-'a']++;
    	nums[s[i-1]-'a'][s[i]-'a']++;
    }
    v32 dp(1 << m, INT_MAX);
    dp[0] = 0;
    forsn(i, 1, 1 << m)
    {
    	forn(j, m)
    	{
    		if((i & (1 << j)) != 0)
    		{
    			int temp = 0;
    			int cnt = 1;
    			forn(k, m)
    			{
    				if(k != j)
    				{
    					if((i & (1 << k)) == 0)
    					{
    						temp -= nums[j][k];
    					}
    					else
    					{
    						temp += nums[j][k];
    						cnt++;
    					}
    				}
    			}
    			temp *= cnt;
    			dp[i] = min(dp[i], dp[(i ^ (1<<j))] + temp);
    		}
    	}
    	// cout<<dp[i]<<'\n';
    }
    cout<<dp[(1 << m)-1]<<'\n';
    return 0;
}