R=range
J=lambda:list(map(int,input().split()))
N,M=J()
E=[J()for m in R(M)]
def c(n):L=R(-15*n,15*n+1);return sum(sum(sum(all(A*x+B*y+C*z+D*n>=0for A,B,C,D in E)for z in L)for y in L)for x in L)
v=[c(n)for n in R(4)]
f=[sum(u[i]*v[i]for i in R(4))for u in[[6,0,0,0],[-11,18,-9,2],[6,-15,12,-3],[-1,3,-3,1]]]
print(-sum(f[i]*(-N)**i for i in R(4))*166374059%998244353)