Build the Trinity Hall Prime
Python 3, 194 bytes



n=int(input())
R=range
w=n//max(i*(i*i&lt;=n&gt;1&gt;n%i)for i in R(1,n))
m=0
for i in R(n):m=m*10+1+7*(abs(i%w*2-w+1)//2*w&gt;i-w)
while any(m%p&lt;1for p in R(2,m)):m+=1
m=str(m)
while m:print(m[:w]);m=m[w:]


Try it online!

too slow for most inputs, especially x &gt; 8

-6 bytes thanks to Jonathan Frech
-98 bytes thanks to Leaky Nun