Language: C

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define N 27
int T,n;
char s[100];
int map[N][N], fg;

void init()
{
    for(int i=0; i<26; i++)
        for(int j=0; j<26; j++)map[i][j]=1;
}

bool loop;
bool vis[26];
int pre[26];

#define clr(a,b)    memset(a,b,sizeof(a))
vector<int> ans;

int gg[55][55];


void dfs(int u)
{
    if(loop == true)    return ;

    for(int i=0; i<26; i++)
    {
        if(map[u][i] == 1)
        {
            if(vis[i] == 1)
            {
                loop = true;

                int cur = u;
                vector<int> tmp;
                int tmplen;
                while(cur != -1)
                {
                    tmp.push_back(cur);
                    cur = pre[cur];
                }
                ans = tmp;

                return ;
            }
            else
            {
                vis[i] = true;
                pre[i] = u;
                dfs(i);
                pre[i] = -1;
                vis[i] = false;
            }
        }
    }
    vector<int> tmp;
    int tmplen;
    int cur = u;
    while(cur != -1)
    {
        tmp.push_back(cur);
        cur = pre[cur];
    }
    if(tmp.size() > ans.size())
        ans = tmp;

}



int main()
{
    freopen("in","r",stdin);
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        init();
        for(int i=0; i<n; i++)
        {
            scanf("%s",s);
            map[s[0]-'a'][s[1]-'a']=0;
        }

        fg=-1;
        for(int i=0; i<26; i++)
        {
            if(map[i][i]==1)
            {
                fg=i;
                break;
            }
        }

        if(~fg)
        {
            for(int i=0; i<20; i++)
            {
                for(int j=0; j<20; j++)
                    printf("%c",fg+'a');
                puts("");
            }
        }
        else
        {
            loop = false;
            for(int i=0; i<26 && loop == false; i++)
            {
                clr(pre, -1);
                clr(vis, false);
                vis[i] = true;
                dfs(i);
            }

            if(loop)
            {
                int pos = 0;
                for(int l=2; l<=40; l++)
                {
                    for(int i=1; i<l; i++)
                    {
                        int j = l - i;
                        gg[i][j] = ans[pos];
                    }
                    pos = (pos + 1) % ans.size();
                }

                for(int i=1; i<=20; i++)
                {
                    for(int j=1; j<=20; j++)
                        printf("%c",gg[i][j]);
                    puts("");
                }

            }
            else
            {
                int len = 0;
                int pos = 0;
                for(int l=2; l<=ans.size()+1; l++)
                {
                    for(int i=1; i<l; i++)
                    {
                        int j = l-i;
                        len = max(len,  min(i,j) );
                        gg[i][j] = ans[pos];
                    }
                    pos++;
                }

                for(int i=1; i<=len; i++)
                {
                    for(int j=1; j<=len; j++)
                        printf("%c",gg[i][j]);
                    puts("");
                }
            }

        }
    }
    return 0;
}

Compiler output:
main.c:3:10: fatal error: algorithm: No such file or directory
    3 | #include <algorithm>
      |          ^~~~~~~~~~~
compilation terminated.