/* Here we let H denote a copy of SL(2,8) and L denote a copy of 2^3.7, the normalizer of a torus.
   This is unique up to conjugacy in G. First we set up L and H. L requires two matrices, and one
   more for H. We give them as elements of GL(27,27^2). Unfortunately, L is very far away from the
   the Magma version of E6. This means that the trilinear form is awful, and will hinder us with our
   calculations. We offer code to confirm that the trilinear form is as suggested, using the function
   CheckE6Form().

   We then construct the centralizer of L in GL(27,F). We can then launch into working out the
   coefficients necessary for the conjugate of h1 (the matrix for H) to lie in our copy of E6, i.e.,
   for the trilinear form to be h1-invariant. After a number of computations we arrive at exactly
   the set of all such elements.

   We then compute the centralizer of L in E6, and then check that the set of elements above is the
   product of the centralizer in GL(27,k) of H and the centralizer of L in E6. This shows that all
   overgroups H of L are C_G(L)-conjugate. */

F<w>:=GF(27^2);

l1:=GL(27,F)![[w^312,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,w^416,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,w^208,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,w^520,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,w^104,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,w^624,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0]];

l2:=GL(27,F)![[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0]];

L:=sub<GL(27,F)|l1,l2>;

h1:=GL(27,F)![[0,2,1,w^50,w^502,w^150,w^410,w^450,w^622,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[1,0,w^273,w^167,w^723,w^683,w^423,w^47,w^323,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[1,w^455,0,w^196,w^588,w^196,w^588,w^308,w^308,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[w^624,w^559,w^560,w^84,0,w^392,w^560,w^84,w^392,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[w^104,w^351,w^224,0,w^252,w^224,w^448,w^252,w^448,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[w^208,w^247,w^560,w^392,w^392,w^84,w^84,0,w^560,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[w^312,w^143,w^224,w^252,w^448,w^448,w^252,w^224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[w^520,w^663,w^672,w^672,w^616,0,w^28,w^28,w^616,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[w^416,w^39,w^672,w^28,w^672,w^616,0,w^616,w^28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,2,1,w^150,w^50,w^450,w^502,w^622,w^410,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,1,0,w^91,w^501,w^713,w^593,w^541,w^141,w^241,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,1,w^637,0,w^588,w^308,w^588,w^308,w^196,w^196,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,w^416,w^221,w^224,w^252,0,w^448,w^224,w^252,w^448,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,w^312,w^325,w^672,0,w^28,w^672,w^616,w^28,w^616,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,w^624,w^13,w^224,w^448,w^448,w^252,w^252,0,w^224,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,w^208,w^429,w^672,w^28,w^616,w^616,w^28,w^672,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,w^104,w^533,w^560,w^560,w^392,0,w^84,w^84,w^392,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,w^520,w^117,w^560,w^84,w^560,w^392,0,w^392,w^84,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,w^502,w^410,w^50,w^622,w^150,w^450],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,w^91,w^541,w^241,w^713,w^141,w^501,w^593],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,w^637,0,w^308,w^196,w^308,w^196,w^588,w^588],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,w^208,w^429,w^672,w^28,0,w^616,w^672,w^28,w^616],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,w^520,w^117,w^560,0,w^84,w^560,w^392,w^84,w^392],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,w^312,w^325,w^672,w^616,w^616,w^28,w^28,0,w^672],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,w^104,w^533,w^560,w^84,w^392,w^392,w^84,w^560,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,w^416,w^221,w^224,w^224,w^448,0,w^252,w^252,w^448],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,w^624,w^13,w^224,w^252,w^224,w^448,0,w^448,w^252]];

x:=GL(27,F)![[w^526,w^12,w^138,w^194,w^604,w^40,w^9,w^35,w^598,w^343,w^497,w^545,w^186,w^185,w^159,w^52,w^52,w^276,w^135,w^312,w^257,w^482,w^274,w^658,w^170,w^156,w^294],
[w^669,w^623,w^385,w^77,w^393,w^548,w^307,w^723,w^65,w^278,w^239,w^540,w^302,w^328,w^329,w^429,w^429,w^471,w^486,w^468,w^63,w^680,w^30,w^593,w^521,w^143,w^229],
[w^419,w^363,w^503,w^685,w^722,w^411,w^285,w^626,w^405,w^664,w^578,w^280,w^621,w^580,w^295,w^106,w^409,w^447,w^412,w^302,w^602,w^87,w^382,w^307,w^531,w^475,w^139],
[w^419,w^643,w^727,0,w^419,w^510,w^6,w^188,w^181,w^76,w^640,w^26,w^44,w^591,w^451,w^670,w^556,w^167,w^692,w^662,w^3,w^502,w^661,w^55,w^531,w^475,w^139],
[w^587,w^699,w^475,w^713,w^70,w^359,w^492,w^21,w^713,w^720,w^186,w^616,w^494,w^461,w^108,w^53,w^31,w^475,w^664,w^180,w^88,w^240,w^704,w^587,w^615,w^195,w^363],
[w^587,w^699,w^475,w^657,w^385,w^267,w^566,w^20,w^293,w^20,w^550,w^252,w^399,w^461,w^554,w^519,w^117,0,w^20,w^13,w^104,w^422,w^197,w^531,w^559,w^307,w^363],
[w^419,w^643,w^727,w^461,w^272,w^727,w^328,w^419,w^461,w^216,w^228,w^411,w^565,w^659,w^558,w^458,w^273,w^223,w^132,w^480,w^380,w^339,w^634,w^167,w^559,w^531,w^111],
[w^419,w^363,w^503,w^657,w^697,w^490,w^573,w^573,w^97,w^720,w^68,w^331,w^693,w^620,w^134,w^465,w^162,w^699,w^636,w^377,w^468,w^13,w^650,w^83,w^559,w^531,w^111],
[w^335,w^475,w^727,w^517,w^566,w^384,w^710,w^459,w^265,w^244,w^572,w^107,w^168,w^646,w^611,w^226,w^456,w^699,w^384,w^527,w^120,w^132,w^405,w^699,w^615,w^195,w^363],
[w^719,w^633,w^283,w^87,w^203,w^382,w^517,w^725,w^571,w^352,w^105,w^462,w^112,w^34,w^115,w^207,w^207,w^697,w^456,w^454,w^409,w^154,w^648,w^387,w^379,w^337,w^23],
[w^420,w^282,w^296,w^464,w^186,w^366,w^39,w^689,w^428,w^157,w^255,w^503,w^544,w^463,w^541,w^610,w^610,w^554,w^53,w^558,w^471,w^496,w^392,w^192,w^704,w^298,w^556],
[w^398,w^230,w^650,w^104,w^189,w^478,w^464,w^421,w^720,w^587,w^173,w^59,w^16,w^335,w^546,w^525,w^316,w^482,w^559,w^385,w^661,w^442,w^313,w^62,w^6,w^566,w^286],
[w^398,w^342,w^594,0,w^398,w^489,w^433,w^615,w^48,w^279,w^99,w^597,w^599,w^498,w^78,w^345,w^575,w^370,w^671,w^425,w^190,w^569,w^344,w^34,w^6,w^566,w^286],
[w^174,w^510,w^566,w^188,w^521,w^634,w^487,w^192,w^188,w^27,w^453,w^339,w^649,w^160,w^687,w^600,w^274,w^566,w^587,w^695,w^523,w^459,w^187,w^174,w^258,w^454,w^230],
[w^174,w^510,w^566,w^20,w^556,w^462,w^657,w^111,w^384,w^111,w^89,w^703,w^234,w^160,w^413,w^490,w^688,0,w^111,w^272,w^363,w^641,w^616,w^6,w^90,w^62,w^230],
[w^398,w^342,w^594,w^160,w^139,w^594,w^307,w^398,w^160,w^699,w^215,w^478,w^576,w^182,w^9,w^645,w^220,w^538,w^447,w^243,w^151,w^470,w^341,w^370,w^90,w^6,w^202],
[w^398,w^230,w^650,w^20,w^348,w^325,w^496,w^496,w^524,w^27,w^359,w^550,w^24,w^663,w^609,w^484,w^693,w^510,w^503,w^636,w^727,w^272,w^181,w^118,w^90,w^6,w^202],
[w^146,w^566,w^594,w^328,w^657,w^475,w^673,w^726,w^300,w^55,w^415,w^606,w^451,w^585,w^662,w^53,w^483,w^510,w^475,w^410,w^203,w^447,w^720,w^510,w^258,w^454,w^230],
[w^347,w^661,w^703,w^115,w^47,w^714,w,w^105,w^7,w^468,w^117,w^642,w^684,w^190,w^199,w^371,w^371,w^21,w^156,w^722,w^717,w^446,w^420,w^391,w^471,w^709,w^27],
[w^152,w^622,w^300,w^76,w^126,w^146,w^595,w^101,w^72,w^689,w^619,w^323,w^4,w^723,w^489,w^254,w^254,w^86,w^273,w^410,w^643,w^484,w^68,w^612,w^588,w^462,w^248],
[w^554,w^50,w^582,w^36,w^369,w^482,w^76,w^233,w^428,w^575,w^529,w^31,w^188,w^547,w^166,w^649,w^464,w^78,w^491,w^229,w^17,w^478,w^221,w^274,w^106,w^330,w^218],
[w^554,w^386,w^414,0,w^554,w^645,w^477,w^659,w^596,w^379,w^359,w^657,w^91,w^646,w^114,w^629,w^331,w^470,w^99,w^557,w^450,w^573,w^548,w^190,w^106,w^330,w^218],
[w^610,w^162,w^330,w^288,w^325,w^14,w^483,w^612,w^288,w^351,w^641,w^143,w^501,w^204,w^667,w^172,w^702,w^330,w^575,w^587,w^487,w^399,w^207,w^610,w^134,w^722,w^50],
[w^610,w^162,w^330,w^512,w^248,w^642,w^421,w^603,w^148,w^603,w^277,w^507,w^374,w^204,w^313,w^726,w^20,0,w^603,w^540,w^631,w^581,w^12,w^106,w^358,w^274,w^50],
[w^554,w^386,w^414,w^204,w^687,w^414,w^463,w^554,w^204,w^183,w^291,w^482,w^412,w^530,w^349,w^177,w^696,w^246,w^155,w^375,w^203,w^562,w^305,w^470,w^358,w^106,w^694],
[w^554,w^50,w^582,w^512,w^144,w^465,w^484,w^484,w^568,w^351,w^307,w^490,w^108,w^179,w^173,w^240,w^425,w^162,w^323,w^176,w^267,w^540,w^449,w^442,w^358,w^106,w^694],
[w^526,w^330,w^414,w^708,w^421,w^239,w^261,w^186,w^624,w^435,w^475,w^658,w^479,w^413,w^98,w^273,w^159,w^162,w^239,w^70,w^47,w^155,w^428,w^162,w^134,w^722,w^50]];

/*
GL(27,9)!(l1^x) in HH;
GL(27,9)!(l2^x) in HH;
GL(27,9)!(h1^x) in HH;
*/




seqs:=[[i,j,k]:i,j,k in [1..NumberOfRows(l1)]|i le j and j le k];

entsnot:=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,
42,43,44,45,46,47,48,49,50,51,52,53,54,61,62,63,70,71,72,79,85,86,88,94,95,97,103,108,109,112,117,118,121,126,130,131,
135,139,140,144,148,151,152,157,160,161,166,169,171,172,178,180,181,187,189,190,191,198,199,200,207,209,210,211,212,213,214,
215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,236,237,238,239,240,241,242,243,250,251,252,
259,265,266,268,274,279,280,283,288,292,293,297,301,304,305,310,313,315,316,322,324,325,326,333,334,335,336,337,338,339,340,
341,342,343,344,345,346,347,348,349,350,351,358,364,369,373,376,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,
393,394,395,396,398,399,400,401,402,403,404,405,412,413,414,421,422,423,430,436,437,439,445,446,448,454,459,460,463,468,469,
472,477,481,482,486,490,491,495,499,502,503,508,511,512,517,520,522,523,529,531,532,538,540,541,542,549,550,551,558,559,560,
561,562,563,564,565,566,567,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,
593,594,601,602,603,610,616,617,619,625,630,631,634,639,643,644,648,652,655,656,661,664,666,667,673,675,676,677,684,685,686,
687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,709,715,720,724,727,729,730,731,732,733,734,735,736,737,738,
746,747,755,779,802,824,845,865,884,885,886,893,894,895,902,903,910,911,912,926,927,1010,1011,1012,1019,1020,1055,1056,1057,
1058,1059,1060,1061,1062,1070,1071,1079,1102,1124,1145,1165,1184,1185,1187,1193,1194,1196,1202,1204,1210,1211,1213,1241,1242,1310,
1311,1313,1319,1321,1355,1356,1357,1358,1359,1360,1361,1369,1370,1378,1400,1421,1441,1460,1461,1464,1469,1470,1473,1478,1481,1486,
1487,1490,1531,1532,1586,1587,1590,1595,1598,1631,1632,1633,1634,1635,1636,1644,1645,1653,1674,1694,1713,1714,1718,1722,1723,1727,
1731,1735,1739,1740,1744,1797,1798,1839,1840,1844,1848,1852,1884,1885,1886,1887,1888,1896,1897,1905,1925,1944,1945,1950,1953,1954,
1959,1962,1967,1970,1971,1976,2040,2041,2070,2071,2076,2079,2084,2115,2116,2117,2118,2126,2127,2135,2154,2155,2161,2163,2164,2170,
2172,2178,2180,2181,2187,2261,2262,2280,2281,2287,2289,2295,2325,2326,2327,2335,2336,2344,2345,2352,2353,2354,2361,2362,2369,2370,
2371,2378,2461,2462,2470,2471,2478,2479,2486,2515,2516,2517,2518,2519,2520,2521,2522,2523,2524,2525,2526,2527,2528,2529,2530,2531,
2532,2533,2534,2535,2536,2537,2538,2539,2540,2541,2542,2543,2544,2545,2546,2547,2548,2549,2550,2557,2558,2559,2566,2572,2573,2575,
2581,2586,2587,2590,2595,2599,2600,2604,2608,2611,2612,2617,2620,2622,2623,2629,2631,2632,2633,2640,2641,2642,2643,2644,2645,2646,
2647,2648,2649,2650,2651,2652,2653,2654,2655,2656,2657,2658,2665,2671,2676,2680,2683,2685,2686,2687,2688,2689,2690,2691,2692,2693,
2694,2695,2696,2697,2698,2699,2700,2701,2702,2703,2710,2711,2712,2719,2725,2726,2728,2734,2739,2740,2743,2748,2752,2753,2757,2761,
2764,2765,2770,2773,2775,2776,2782,2784,2785,2786,2793,2795,2796,2797,2798,2799,2800,2801,2802,2803,2804,2805,2806,2807,2808,2809,
2810,2811,2818,2824,2829,2833,2836,2838,2839,2840,2841,2842,2843,2844,2845,2846,2847,2855,2870,2884,2897,2909,2920,2930,2931,2932,
2939,2940,2975,2976,2977,2978,2979,2980,2981,2982,2990,3004,3017,3029,3040,3050,3051,3053,3059,3061,3095,3096,3097,3098,3099,3100,
3101,3109,3122,3134,3145,3155,3156,3159,3164,3167,3200,3201,3202,3203,3204,3205,3213,3225,3236,3246,3247,3251,3255,3259,3291,3292,
3293,3294,3295,3303,3314,3324,3325,3330,3333,3338,3369,3370,3371,3372,3380,3390,3391,3397,3399,3405,3435,3436,3437,3445,3446,3453,
3454,3461,3490,3491,3492,3493,3494,3495,3496,3497,3498,3499,3500,3501,3502,3503,3504,3505,3506,3507,3514,3520,3525,3529,3532,3534,
3535,3536,3537,3538,3539,3540,3541,3542,3543,3550,3556,3561,3565,3568,3570,3571,3572,3573,3574,3575,3576,3577,3578,3584,3589,3593,
3596,3598,3599,3600,3601,3602,3603,3604,3605,3610,3614,3617,3619,3620,3621,3622,3623,3624,3625,3629,3632,3634,3635,3636,3637,3638,
3639,3642,3644,3645,3646,3647,3648,3650,3651,3652,3653,3654];
ents:=[i:i in [1..#seqs]|not(i in entsnot)];

vals:=[1,w^104,w^416,w^624,w^208,w^312,w^35,w^139,w^451,w^659,w^243,w^347,w^268,w^372,w^684,w^164,w^476,w^580,w^312,w^520,w^208,w^624,w^104,
w^35,w^347,w^555,w^243,w^659,w^139,w^268,w^580,w^60,w^476,w^164,w^372,w^208,w^520,w^416,1,w^139,w^347,w^243,w^555,w^451,w^35,w^372,
w^580,w^476,w^60,w^684,w^268,w^312,w^104,w^624,w^451,w^555,w^243,w^347,w^139,w^659,w^684,w^60,w^476,w^580,w^372,w^164,1,w^416,w^659,
w^243,w^555,w^347,w^35,w^451,w^164,w^476,w^60,w^580,w^268,w^684,w^520,w^243,w^659,w^451,w^139,w^35,w^555,w^476,w^164,w^684,w^372,w^268,
w^60,w^347,w^139,w^35,w^659,w^451,w^555,w^580,w^372,w^268,w^164,w^684,w^60,w^681,w^641,w^70,w^174,w^486,w^694,w^278,w^382,w^303,w^407,
w^719,w^199,w^511,w^615,w^382,w^590,w^278,w^694,w^174,w^303,w^615,w^95,w^511,w^199,w^407,w^278,w^590,w^486,w^70,w^407,w^615,w^511,w^95,
w^719,w^303,w^382,w^174,w^694,w^719,w^95,w^511,w^615,w^407,w^199,w^70,w^486,w^199,w^511,w^95,w^615,w^303,w^719,w^590,w^511,w^199,w^719,
w^407,w^303,w^95,w^615,w^407,w^303,w^199,w^719,w^95,w^536,w^640,w^224,w^432,w^16,w^120,w^120,w^328,w^16,w^432,w^640,w^16,w^328,w^224,
w^536,w^120,w^640,w^432,w^536,w^224,w^328,w^151,w^221,w^117,w^533,w^325,w^13,w^637,w^74,w^698,w^386,w^178,w^594,w^490,w^34,w^658,w^346,
w^138,w^554,w^450,w^637,w^429,w^13,w^325,w^117,w^74,w^490,w^282,w^594,w^178,w^698,w^34,w^450,w^242,w^554,w^138,w^658,w^13,w^429,w^533,
w^221,w^698,w^490,w^594,w^282,w^386,w^74,w^658,w^450,w^554,w^242,w^346,w^34,w^637,w^117,w^325,w^386,w^282,w^594,w^490,w^698,w^178,
w^346,w^242,w^554,w^450,w^658,w^138,w^221,w^533,w^178,w^594,w^282,w^490,w^74,w^386,w^138,w^554,w^242,w^450,w^34,w^346,w^429,w^594,
w^178,w^386,w^698,w^74,w^282,w^554,w^138,w^346,w^658,w^34,w^242,w^490,w^698,w^74,w^178,w^386,w^282,w^450,w^658,w^34,w^138,w^346,w^242,
w^459,w^382,w^278,w^694,w^486,w^174,w^70,w^433,w^329,w^17,w^537,w^225,w^121,w^70,w^590,w^174,w^486,w^278,w^433,w^121,w^641,w^225,w^537,
w^329,w^174,w^590,w^694,w^382,w^329,w^121,w^225,w^641,w^17,w^433,w^70,w^278,w^486,w^17,w^641,w^225,w^121,w^329,w^537,w^382,w^694,w^537,
w^225,w^641,w^121,w^433,w^17,w^590,w^225,w^537,w^17,w^329,w^433,w^641,w^121,w^329,w^433,w^537,w^17,w^641,w^211,w^107,w^523,w^315,w^3,
w^627,w^627,w^419,w^3,w^315,w^107,w^3,w^419,w^523,w^211,w^627,w^107,w^315,w^211,w^523,w^419,w^100,w^464,w^464,w^464,w^464,w^464,w^464,
w^424,w^60,w^60,w^60,w^60,w^60,w^60,w^338,w^338,w^338,w^338,w^338,w^87,w^568,w^464,w^464,w^576,w^72,w^16,w^16,w^576,w^190,w^658,w^60,
w^60,w^390,w^582,w^118,w^118,w^390,w^338,w^338,w^338,w^338,w^399,w^256,w^464,w^16,w^464,w^576,w^72,w^576,w^16,w^710,w^138,w^60,w^118,
w^60,w^390,w^582,w^390,w^118,w^338,w^338,w^338,w^607,w^48,w^464,w^576,w^72,w^464,w^16,w^72,w^16,w^86,w^34,w^60,w^390,w^582,w^60,w^118,
w^582,w^118,w^338,w^338,w^503,w^152,w^464,w^576,w^16,w^72,w^464,w^576,w^72,w^398,w^450,w^60,w^390,w^118,w^582,w^60,w^390,w^582,w^338,
w^711,w^672,w^464,w^72,w^16,w^16,w^72,w^464,w^576,w^502,w^346,w^60,w^582,w^118,w^118,w^582,w^60,w^390,w^295,w^360,w^464,w^72,w^72,
w^576,w^576,w^16,w^464,w^294,w^554,w^60,w^582,w^582,w^390,w^390,w^118,w^60,w^304,w^616,w^96,w^720,w^200,w^512,w^264,w^576,w^56,w^680,
w^160,w^472,w^694,w^382,w^174,w^278,w^70,w^486,w^290,w^706,w^498,w^602,w^394,w^82,w^135,w^499,w^499,w^499,w^499,w^499,w^499,w^277,
w^641,w^641,w^641,w^641,w^641,w^641,w^499,w^557,w^101,w^557,w^293,w^101,w^680,w^602,w^641,w^641,w^368,w^368,w^324,w^368,w^444,w^499,
w^101,w^293,w^557,w^293,w^472,w^82,w^641,w^324,w^641,w^444,w^700,w^368,w^368,w^499,w^293,w^293,w^557,w^576,w^706,w^641,w^444,w^368,
w^641,w^368,w^700,w^324,w^499,w^101,w^101,w^160,w^394,w^641,w^368,w^368,w^700,w^641,w^444,w^368,w^499,w^557,w^264,w^290,w^641,w^700,
w^324,w^368,w^368,w^641,w^368,w^499,w^56,w^498,w^641,w^368,w^700,w^368,w^444,w^324,w^641,w^276,w^68,w^172,w^484,w^588,w^380,w^289,
w^497,w^393,w^81,w^705,w^185,w^55,w^419,w^419,w^419,w^419,w^419,w^419,w^419,w^531,w^27,w^531,w^699,w^27,w^419,w^27,w^699,w^531,w^699,
w^419,w^699,w^699,w^531,w^419,w^27,w^27,w^419,w^531,w^419,w^464,w^100,w^464,w^464,w^464,w^464,w^464,w^60,w^424,w^60,w^60,w^60,w^60,
w^60,w^338,w^338,w^338,w^338,w^295,w^360,w^72,w^464,w^464,w^16,w^16,w^576,w^72,w^294,w^554,w^582,w^60,w^60,w^118,w^118,w^390,w^582,
w^338,w^338,w^338,w^191,w^464,w^16,w^464,w^72,w^464,w^72,w^576,w^576,w^606,w^242,w^118,w^60,w^582,w^60,w^582,w^390,w^390,w^338,w^338,
w^711,w^672,w^72,w^464,w^576,w^576,w^464,w^72,w^16,w^502,w^346,w^582,w^60,w^390,w^390,w^60,w^582,w^118,w^338,w^503,w^152,w^576,w^464,
w^72,w^16,w^576,w^464,w^16,w^398,w^450,w^390,w^60,w^582,w^118,w^390,w^60,w^118,w^399,w^256,w^16,w^464,w^16,w^72,w^576,w^72,w^464,
w^710,w^138,w^118,w^60,w^118,w^582,w^390,w^582,w^60,w^304,w^512,w^408,w^200,w^720,w^616,w^264,w^472,w^368,w^160,w^680,w^576,w^694,
w^486,w^590,w^70,w^278,w^382,w^290,w^82,w^186,w^394,w^602,w^706,w^499,w^499,w^101,w^293,w^293,w^557,w^557,w^680,w^602,w^641,w^641,
w^444,w^700,w^368,w^324,w^368,w^135,w^499,w^499,w^499,w^499,w^499,w^641,w^277,w^641,w^641,w^641,w^641,w^641,w^499,w^293,w^557,w^101,
w^293,w^56,w^498,w^368,w^641,w^641,w^368,w^324,w^444,w^700,w^499,w^101,w^557,w^101,w^368,w^186,w^368,w^641,w^700,w^641,w^368,w^368,
w^444,w^499,w^101,w^557,w^264,w^290,w^700,w^641,w^368,w^444,w^641,w^368,w^324,w^499,w^293,w^160,w^394,w^368,w^641,w^368,w^324,w^444,
w^641,w^368,w^499,w^472,w^82,w^324,w^641,w^368,w^368,w^368,w^700,w^641,w^276,w^380,w^692,w^588,w^484,w^68,w^289,w^185,w^601,w^705,w^81,
w^497,w^419,w^419,w^27,w^699,w^699,w^531,w^531,w^55,w^419,w^419,w^419,w^419,w^419,w^419,w^699,w^531,w^27,w^699,w^419,w^27,w^531,w^27,
w^419,w^27,w^531,w^419,w^699,w^419,w^464,w^464,w^100,w^464,w^464,w^464,w^464,w^60,w^60,w^424,w^60,w^60,w^60,w^60,w^338,w^338,w^338,
w^711,w^672,w^16,w^576,w^464,w^464,w^576,w^16,w^72,w^502,w^346,w^118,w^390,w^60,w^60,w^390,w^118,w^582,w^338,w^338,w^191,w^464,w^576,
w^72,w^464,w^72,w^464,w^16,w^16,w^606,w^242,w^390,w^582,w^60,w^582,w^60,w^118,w^118,w^338,w^607,w^48,w^72,w^16,w^464,w^72,w^576,w^464,
w^576,w^86,w^34,w^582,w^118,w^60,w^582,w^390,w^60,w^390,w^87,w^568,w^576,w^576,w^464,w^16,w^72,w^72,w^464,w^190,w^658,w^390,w^390,
w^60,w^118,w^582,w^582,w^60,w^616,w^512,w^200,w^408,w^96,w^304,w^576,w^472,w^160,w^368,w^56,w^264,w^382,w^486,w^70,w^590,w^174,w^694,
w^706,w^82,w^394,w^186,w^498,w^290,w^499,w^293,w^499,w^557,w^101,w^101,w^557,w^472,w^82,w^641,w^368,w^641,w^368,w^368,w^444,w^324,
w^499,w^499,w^557,w^293,w^557,w^101,w^56,w^498,w^700,w^641,w^641,w^324,w^368,w^368,w^368,w^135,w^499,w^499,w^499,w^499,w^641,w^641,
w^277,w^641,w^641,w^641,w^641,w^499,w^101,w^293,w^293,w^264,w^290,w^324,w^368,w^641,w^641,w^444,w^368,w^700,w^499,w^557,w^293,w^368,
w^186,w^444,w^700,w^641,w^368,w^641,w^324,w^368,w^499,w^101,w^576,w^706,w^368,w^324,w^641,w^700,w^368,w^641,w^444,w^499,w^680,w^602,
w^368,w^444,w^641,w^368,w^700,w^368,w^641,w^68,w^380,w^588,w^692,w^172,w^276,w^497,w^185,w^705,w^601,w^393,w^289,w^419,w^699,w^419,
w^531,w^27,w^27,w^531,w^419,w^419,w^531,w^699,w^531,w^27,w^55,w^419,w^419,w^419,w^419,w^419,w^27,w^699,w^699,w^419,w^531,w^699,w^419,
w^27,w^419,w^464,w^464,w^464,w^100,w^464,w^464,w^464,w^60,w^60,w^60,w^424,w^60,w^60,w^60,w^338,w^338,w^295,w^360,w^576,w^16,w^16,
w^464,w^464,w^72,w^576,w^294,w^554,w^390,w^118,w^118,w^60,w^60,w^582,w^390,w^338,w^399,w^256,w^576,w^72,w^576,w^464,w^16,w^464,w^72,
w^710,w^138,w^390,w^582,w^390,w^60,w^118,w^60,w^582,w^503,w^152,w^72,w^16,w^576,w^464,w^72,w^16,w^464,w^398,w^450,w^582,w^118,w^390,
w^60,w^582,w^118,w^60,w^96,w^408,w^200,w^512,w^616,w^720,w^56,w^368,w^160,w^472,w^576,w^680,w^174,w^590,w^70,w^486,w^382,w^278,w^498,
w^186,w^394,w^82,w^706,w^602,w^499,w^557,w^293,w^499,w^557,w^101,w^293,w^576,w^706,w^641,w^368,w^700,w^641,w^324,w^368,w^368,w^499,
w^101,w^499,w^293,w^101,w^557,w^368,w^186,w^324,w^641,w^368,w^641,w^700,w^444,w^368,w^499,w^499,w^557,w^557,w^101,w^264,w^290,w^368,
w^444,w^641,w^641,w^368,w^324,w^368,w^135,w^499,w^499,w^499,w^641,w^641,w^641,w^277,w^641,w^641,w^641,w^499,w^293,w^101,w^56,w^498,
w^368,w^368,w^324,w^641,w^641,w^700,w^444,w^499,w^293,w^472,w^82,w^444,w^368,w^368,w^641,w^368,w^641,w^700,w^499,w^160,w^394,w^700,
w^324,w^444,w^641,w^368,w^368,w^641,w^172,w^692,w^588,w^380,w^68,w^484,w^393,w^601,w^705,w^185,w^497,w^81,w^419,w^531,w^699,w^419,
w^531,w^27,w^699,w^419,w^27,w^419,w^699,w^27,w^531,w^419,w^419,w^531,w^531,w^27,w^55,w^419,w^419,w^419,w^419,w^699,w^27,w^419,w^699,
w^419,w^464,w^464,w^464,w^464,w^100,w^464,w^464,w^60,w^60,w^60,w^60,w^424,w^60,w^60,w^338,w^87,w^568,w^16,w^16,w^72,w^576,w^464,w^464,
w^72,w^190,w^658,w^118,w^118,w^582,w^390,w^60,w^60,w^582,w^607,w^48,w^16,w^72,w^576,w^16,w^464,w^576,w^464,w^86,w^34,w^118,w^582,
w^390,w^118,w^60,w^390,w^60,w^720,w^200,w^408,w^512,w^304,w^96,w^680,w^160,w^368,w^472,w^264,w^56,w^278,w^70,w^590,w^486,w^694,w^174,
w^602,w^394,w^186,w^82,w^290,w^498,w^499,w^101,w^557,w^101,w^499,w^557,w^293,w^160,w^394,w^641,w^444,w^324,w^368,w^641,w^368,w^700,
w^499,w^101,w^557,w^499,w^293,w^293,w^264,w^290,w^368,w^641,w^444,w^368,w^641,w^700,w^368,w^499,w^293,w^499,w^293,w^557,w^368,w^186,
w^368,w^368,w^641,w^700,w^641,w^368,w^324,w^499,w^499,w^101,w^557,w^56,w^498,w^444,w^324,w^368,w^641,w^641,w^368,w^368,w^135,w^499,
w^499,w^641,w^641,w^641,w^641,w^277,w^641,w^641,w^499,w^101,w^680,w^602,w^324,w^368,w^700,w^444,w^641,w^641,w^368,w^499,w^576,w^706,
w^368,w^700,w^368,w^324,w^641,w^444,w^641,w^484,w^588,w^692,w^380,w^276,w^172,w^81,w^705,w^601,w^185,w^289,w^393,w^419,w^27,w^531,w^27,
w^419,w^531,w^699,w^419,w^27,w^531,w^419,w^699,w^699,w^419,w^699,w^419,w^699,w^531,w^419,w^419,w^27,w^531,w^55,w^419,w^419,w^419,w^27,
w^419,w^464,w^464,w^464,w^464,w^464,w^100,w^464,w^60,w^60,w^60,w^60,w^60,w^424,w^60,w^191,w^464,w^72,w^576,w^16,w^576,w^16,w^464,
w^464,w^606,w^242,w^582,w^390,w^118,w^390,w^118,w^60,w^60,w^200,w^720,w^96,w^616,w^304,w^408,w^160,w^680,w^56,w^576,w^264,w^368,w^70,
w^278,w^174,w^382,w^694,w^590,w^394,w^602,w^498,w^706,w^290,w^186,w^499,w^101,w^293,w^557,w^293,w^499,w^101,w^264,w^290,w^641,w^368,
w^368,w^324,w^700,w^641,w^444,w^499,w^293,w^293,w^557,w^499,w^557,w^160,w^394,w^444,w^641,w^700,w^368,w^368,w^641,w^324,w^499,w^101,
w^101,w^499,w^557,w^576,w^706,w^700,w^368,w^641,w^368,w^444,w^641,w^368,w^499,w^557,w^499,w^101,w^472,w^82,w^368,w^700,w^444,w^641,
w^324,w^641,w^368,w^499,w^499,w^293,w^680,w^602,w^368,w^324,w^368,w^368,w^641,w^641,w^700,w^135,w^499,w^641,w^641,w^641,w^641,w^641,
w^277,w^641,w^499,w^368,w^186,w^368,w^368,w^324,w^444,w^368,w^641,w^641,w^588,w^484,w^172,w^68,w^276,w^692,w^705,w^81,w^393,w^497,
w^289,w^601,w^419,w^27,w^699,w^531,w^699,w^419,w^27,w^419,w^699,w^699,w^531,w^419,w^531,w^419,w^27,w^27,w^419,w^531,w^419,w^531,w^419,
w^27,w^419,w^419,w^699,w^55,w^419,w^419,w^464,w^464,w^464,w^464,w^464,w^464,w^100,w^60,w^60,w^60,w^60,w^60,w^60,w^424,w^512,w^616,
w^304,w^720,w^96,w^408,w^472,w^576,w^264,w^680,w^56,w^368,w^486,w^382,w^694,w^278,w^174,w^590,w^82,w^706,w^290,w^602,w^498,w^186,w^499,
w^293,w^101,w^101,w^557,w^293,w^499,w^56,w^498,w^641,w^700,w^368,w^444,w^368,w^368,w^641,w^499,w^557,w^293,w^101,w^101,w^499,w^472,
w^82,w^368,w^641,w^324,w^700,w^444,w^368,w^641,w^499,w^557,w^101,w^293,w^499,w^680,w^602,w^444,w^368,w^641,w^324,w^368,w^700,w^641,
w^499,w^293,w^557,w^499,w^160,w^394,w^368,w^368,w^368,w^641,w^700,w^324,w^641,w^499,w^557,w^499,w^576,w^706,w^324,w^368,w^444,w^368,
w^641,w^368,w^641,w^499,w^499,w^368,w^186,w^700,w^444,w^368,w^368,w^324,w^641,w^641,w^135,w^641,w^641,w^641,w^641,w^641,w^641,w^277,
w^380,w^68,w^276,w^484,w^172,w^692,w^185,w^497,w^289,w^81,w^393,w^601,w^419,w^699,w^27,w^27,w^531,w^699,w^419,w^419,w^531,w^699,w^27,
w^27,w^419,w^419,w^531,w^27,w^699,w^419,w^419,w^699,w^531,w^419,w^419,w^531,w^419,w^419,w^419,w^55,w^157,w^469,w^677,w^573,w^53,w^365,
w^299,w^611,w^91,w^715,w^195,w^507,w^365,w^261,w^53,w^573,w^469,w^299,w^507,w^403,w^195,w^715,w^611,w^53,w^261,w^677,w^157,w^611,w^507,
w^195,w^403,w^91,w^299,w^365,w^469,w^573,w^91,w^403,w^195,w^507,w^611,w^715,w^157,w^677,w^715,w^195,w^403,w^507,w^299,w^91,w^261,
w^195,w^715,w^91,w^611,w^299,w^403,w^507,w^611,w^299,w^715,w^91,w^403,w^168,w^480,w^688,w^584,w^64,w^376,w^376,w^272,w^64,w^584,
w^480,w^64,w^272,w^688,w^168,w^376,w^480,w^584,w^168,w^688,w^272,w^92,w^508,w^300,w^404,w^196,w^612,w^416,w^104,w^624,1,w^520,w^208,
w^612,w^716,w^196,w^404,w^508,w^416,w^208,w^312,w^520,1,w^104,w^196,w^716,w^300,w^92,w^104,w^208,w^520,w^312,w^624,w^416,w^612,w^508,
w^404,w^624,w^312,w^520,w^208,w^104,1,w^92,w^300,1,w^520,w^312,w^208,w^416,w^624,w^716,w^520,1,w^624,w^104,w^416,w^312,w^208,w^104,
w^416,1,w^624,w^312,w^727,w^12,w^428,w^220,w^324,w^116,w^532,w^532,w^636,w^116,w^324,w^428,w^116,w^636,w^220,w^12,w^532,w^428,w^324,
w^12,w^220,w^636,w^494,w^130,w^130,w^130,w^130,w^130,w^130,w^443,w^443,w^443,w^443,w^443,w^169,w^546,w^130,w^130,w^466,w^410,w^242,
w^242,w^466,w^443,w^443,w^443,w^443,w^689,w^26,w^130,w^242,w^130,w^466,w^410,w^466,w^242,w^443,w^443,w^443,w^65,w^650,w^130,w^466,
w^410,w^130,w^242,w^410,w^242,w^443,w^443,w^377,w^338,w^130,w^466,w^242,w^410,w^130,w^466,w^410,w^443,w^481,w^234,w^130,w^410,w^242,
w^242,w^410,w^130,w^466,w^273,w^442,w^130,w^410,w^410,w^466,w^466,w^242,w^130,w^675,w^467,w^571,w^155,w^259,w^51,w^233,w^441,w^337,
w^25,w^649,w^129,w^90,w^454,w^454,w^454,w^454,w^454,w^454,w^454,w^56,w^248,w^56,w^512,w^248,w^454,w^248,w^512,w^56,w^512,w^454,w^512,
w^512,w^56,w^454,w^248,w^248,w^454,w^56,w^454,w^130,w^494,w^130,w^130,w^130,w^130,w^130,w^443,w^443,w^443,w^443,w^273,w^442,w^410,
w^130,w^130,w^242,w^242,w^466,w^410,w^443,w^443,w^443,w^585,w^130,w^242,w^130,w^410,w^130,w^410,w^466,w^466,w^443,w^443,w^481,w^234,
w^410,w^130,w^466,w^466,w^130,w^410,w^242,w^443,w^377,w^338,w^466,w^130,w^410,w^242,w^466,w^130,w^242,w^689,w^26,w^242,w^130,w^242,
w^410,w^466,w^410,w^130,w^675,w^51,w^363,w^259,w^155,w^467,w^233,w^129,w^545,w^649,w^25,w^441,w^454,w^454,w^248,w^512,w^512,w^56,w^56,
w^90,w^454,w^454,w^454,w^454,w^454,w^454,w^512,w^56,w^248,w^512,w^454,w^248,w^56,w^248,w^454,w^248,w^56,w^454,w^512,w^454,w^130,w^130,
w^494,w^130,w^130,w^130,w^130,w^443,w^443,w^443,w^481,w^234,w^242,w^466,w^130,w^130,w^466,w^242,w^410,w^443,w^443,w^585,w^130,w^466,
w^410,w^130,w^410,w^130,w^242,w^242,w^443,w^65,w^650,w^410,w^242,w^130,w^410,w^466,w^130,w^466,w^169,w^546,w^466,w^466,w^130,w^242,
w^410,w^410,w^130,w^467,w^51,w^259,w^363,w^571,w^675,w^441,w^129,w^649,w^545,w^337,w^233,w^454,w^512,w^454,w^56,w^248,w^248,w^56,w^454,
w^454,w^56,w^512,w^56,w^248,w^90,w^454,w^454,w^454,w^454,w^454,w^248,w^512,w^512,w^454,w^56,w^512,w^454,w^248,w^454,w^130,w^130,w^130,
w^494,w^130,w^130,w^130,w^443,w^443,w^273,w^442,w^466,w^242,w^242,w^130,w^130,w^410,w^466,w^443,w^689,w^26,w^466,w^410,w^466,w^130,
w^242,w^130,w^410,w^377,w^338,w^410,w^242,w^466,w^130,w^410,w^242,w^130,w^571,w^363,w^259,w^51,w^467,w^155,w^337,w^545,w^649,w^129,
w^441,w^25,w^454,w^56,w^512,w^454,w^56,w^248,w^512,w^454,w^248,w^454,w^512,w^248,w^56,w^454,w^454,w^56,w^56,w^248,w^90,w^454,w^454,
w^454,w^454,w^512,w^248,w^454,w^512,w^454,w^130,w^130,w^130,w^130,w^494,w^130,w^130,w^443,w^169,w^546,w^242,w^242,w^410,w^466,w^130,
w^130,w^410,w^65,w^650,w^242,w^410,w^466,w^242,w^130,w^466,w^130,w^155,w^259,w^363,w^51,w^675,w^571,w^25,w^649,w^545,w^129,w^233,w^337,
w^454,w^248,w^56,w^248,w^454,w^56,w^512,w^454,w^248,w^56,w^454,w^512,w^512,w^454,w^512,w^454,w^512,w^56,w^454,w^454,w^248,w^56,w^90,
w^454,w^454,w^454,w^248,w^454,w^130,w^130,w^130,w^130,w^130,w^494,w^130,w^585,w^130,w^410,w^466,w^242,w^466,w^242,w^130,w^130,w^259,
w^155,w^571,w^467,w^675,w^363,w^649,w^25,w^337,w^441,w^233,w^545,w^454,w^248,w^512,w^56,w^512,w^454,w^248,w^454,w^512,w^512,w^56,w^454,
w^56,w^454,w^248,w^248,w^454,w^56,w^454,w^56,w^454,w^248,w^454,w^454,w^512,w^90,w^454,w^454,w^130,w^130,w^130,w^130,w^130,w^130,w^494,
w^51,w^467,w^675,w^155,w^571,w^363,w^129,w^441,w^233,w^25,w^337,w^545,w^454,w^512,w^248,w^248,w^56,w^512,w^454,w^454,w^56,w^512,w^248,
w^248,w^454,w^454,w^56,w^248,w^512,w^454,w^454,w^512,w^56,w^454,w^454,w^56,w^454,w^454,w^454,w^90,w^89,w^609,w^713,w^297,w^401,w^193,
w^193,w^505,w^401,w^297,w^609,w^401,w^505,w^713,w^89,w^193,w^609,w^297,w^89,w^713,w^505,w^648,w^128,w^24,w^440,w^336,w^544,w^544,w^232,
w^336,w^440,w^128,w^336,w^232,w^24,w^648,w^544,w^128,w^440,w^648,w^24,w^232,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,
w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,w^687,
w^687,w^687,w^687,w^687];

f27:=[F!0:i in [1..#seqs]];
for i in [1..#ents] do f27[ents[i]]:=vals[i]; end for;

R<a,b,c,d,e,f,m1,m2,m3,m4,m5,m6,m7,m8,m9>:=PolynomialRing(F,15);
mats:=MatrixRing(R,NumberOfRows(l1));

scal:=mats!1;
scal[1,1]:=a;
scal[2,2]:=b;
scal[10,10]:=c;
scal[11,11]:=d;
scal[19,19]:=e;
scal[20,20]:=f;
for i in [3..9] do scal[i,i]:=m1; scal[i+9,i+9]:=m5; scal[i+18,i+18]:=m9; scal[i,i+9]:=m2; scal[i,i+18]:=m3; scal[i+9,i]:=m4; scal[i+9,i+18]:=m6; scal[i+18,i]:=m7; scal[i+18,i+9]:=m8; end for;



function Matricise(v)
return Matrix(1,NumberOfColumns(v),[R!v[i]:i in [1..NumberOfColumns(v)]]);
end function;

// We now show that g, which is the second generator of H (the first lies in L, so is fine) satisfies the equations mentioned
V:=GModule(L);
g:=mats!h1;

rels:=[];

/*
function ProduceRel(seq)

u:=V.seq[1]; v:=V.seq[2]; w:=V.seq[3];
u1:=Matricise(u)*scal; v1:=Matricise(v)*scal; w1:=Matricise(w)*scal;
u2:=Matricise(u)*g*scal; v2:=Matricise(v)*g*scal; w2:=Matricise(w)*g*scal;
e1:=&+[u1[1,i]*v1[1,j]*w1[1,k]*f27[Position(seqs,Sort([i,j,k]))]:i,j,k in [1..NumberOfRows(g)]];
e2:=&+[u2[1,i]*v2[1,j]*w2[1,k]*f27[Position(seqs,Sort([i,j,k]))]:i,j,k in [1..NumberOfRows(g)]];

return e1-e2;
end function;
*/

intseqs1:=[seqs[i]:i in ents];
intseqs:=&join{{[i[1],i[2],i[3]],[i[1],i[3],i[2]],[i[2],i[1],i[3]],[i[2],i[3],i[1]],[i[3],i[1],i[2]],[i[3],i[2],i[1]]}:i in intseqs1};

function ProdRel(seq)

u:=V.seq[1]; v:=V.seq[2]; w:=V.seq[3];
u1:=Matricise(u)*scal; v1:=Matricise(v)*scal; w1:=Matricise(w)*scal;
u2:=Matricise(u)*g*scal; v2:=Matricise(v)*g*scal; w2:=Matricise(w)*g*scal;
e1:=&+[u1[1,i[1]]*v1[1,i[2]]*w1[1,i[3]]*f27[Position(seqs,Sort([i[1],i[2],i[3]]))]:i in intseqs];
e2:=&+[u2[1,i[1]]*v2[1,i[2]]*w2[1,i[3]]*f27[Position(seqs,Sort([i[1],i[2],i[3]]))]:i in intseqs];

return e1-e2;
end function;

function CheckRel(seq,gg)
u:=V.seq[1]; v:=V.seq[2]; w:=V.seq[3];
u1:=Matricise(u); v1:=Matricise(v); w1:=Matricise(w);
u2:=Matricise(u)*mats!gg; v2:=Matricise(v)*mats!gg; w2:=Matricise(w)*mats!gg;
e1:=&+[u1[1,i[1]]*v1[1,i[2]]*w1[1,i[3]]*f27[Position(seqs,Sort([i[1],i[2],i[3]]))]:i in intseqs];
e2:=&+[u2[1,i[1]]*v2[1,i[2]]*w2[1,i[3]]*f27[Position(seqs,Sort([i[1],i[2],i[3]]))]:i in intseqs];
return e1-e2;
end function;

coeffs0:=[a,b,c,d,e,f,m1,m2,m3,m4,m5,m6,m7,m8,m9];

function ChangeCoefficient(coeffs,coeff,target)
coeffs2:=coeffs;
nn:=Position(coeffs0,coeff);
coeffs2[nn]:=target;
return [Evaluate(i,coeffs2):i in coeffs];
end function;

function ChangeCoefficients(coeffs,coeff,target)
coeffs2:=coeffs;
for i in [1..#coeff] do
  nn:=Position(coeffs0,coeff[i]);
  coeffs2[nn]:=target[i];
end for;
return [Evaluate(i,coeffs2):i in coeffs];
end function;

// This function automatically replaces all variables that appear as the leading term
// in a linear equation by the rest of the expression.

function ChangeLinearCoefficients(coeffs,rels)

relsd:=[i:i in rels|Degree(LeadingTerm(i)) eq 1];
return ChangeCoefficients(coeffs,[LeadingTerm(i):i in relsd],[-i+LeadingTerm(i):i in relsd]);

end function;

// This function removes all powers from all polynomials in B, and removes all factors from
// polynomials in B that lie in X. (Here X should be a set of polynomials known to be
// non-zero.)

function SimplifyBasis(B,X)

if B eq [] or B eq [1] then return B; end if;
Bfact:={Factorization(i):i in B|i ne 0};
Bfact2:={[i[1]:i in j|not(i[1] in X)]:j in Bfact};
// If any of the polynomials are now 1 then the basis dies: 
if(Minimum([#i:i in Bfact2]) eq 0) then return [1]; end if;
B2:=[&*i:i in Bfact2];
return B2;
end function;


// The fast method first determines some of the relations, reduces the system, and then repeatedly
// takes Groebner bases and simplification to end up with the answer.

function QuickCheckDetermination()

// Since we may multiply scal by any matrix that centralizes H, we may assume that b=c=e=1. We can then
// multiply by a diagonal element at the end to produce all elements of GL(27,k) that map h1 into G.

coeffs0a:=[a,1,1,d,1,f,m1,m2,m3,m4,m5,m6,m7,m8,m9];

// We need some relations. Because they take a long time to compute, we do the first 75 of them and
// a few chosen other ones.

rels:=[ProdRel([1,1,3]),ProdRel([11,11,12]),ProdRel([20,20,21]),ProdRel([2,2,20]),ProdRel([1,2,3]),
ProdRel([1,10,10]),ProdRel([10,10,12]),ProdRel([11,19,19]),ProdRel([19,19,21]),ProdRel([2,2,12]),
ProdRel([10,10,21]),ProdRel([3,19,19]),ProdRel([1,3,19]),ProdRel([10,20,21]),ProdRel([2,11,12]),
ProdRel([1,2,12]),ProdRel([10,11,21]),ProdRel([3,19,20])];

for i in [1..75] do Append(~rels,ProdRel(seqs[i])); end for;

rels2:=[Evaluate(i,coeffs0a):i in rels];

B2:=GroebnerBasis(ChangeOrder(ideal<R|rels2>,"grevlex")); B2:=SimplifyBasis(B2,[a,d,f]);
B2:=GroebnerBasis([R!i:i in B2]);
B2 eq 
[
    a + w^182*m5 + w^597*m6 + w^273,
    d + w^404*m8 + w^637*m9 + w^455,
    f + w^217*m2 + w^177*m3 + 2,
    m1 + w^672*m2 + w^359*m3 + 2,
    m2*m5 + w^273*m2 + w^284*m3*m6 + w^415*m3 + w^329*m5 + w^380*m6 + w^693,
    m2*m6 + w^40*m2 + w^688*m3*m6 + w^91*m3 + w^147*m6,
    m2*m8 + w^233*m2 + w^102*m3*m9 + w^557*m3 + w^602*m8 + w^198*m9 + w^562,
    m2*m9 + w^273*m2 + w^233*m3*m9 + w^688*m3 + w^693*m9 + w^329,
    m3*m5 + w^688*m3*m6 + w^546*m3 + w^642*m5 + w^56*m6 + w^278,
    m3*m6*m9 + 2*m3*m6 + w^495*m3*m9 + w^677*m3 + w^5*m6*m9 + w^187*m6 + w^318*m9 + w^682,
    m3*m8 + w^233*m3*m9 + w^51*m3 + w^278*m8 + w^329*m9 + w^693,
    m4 + w^35*m5 + w^268*m6 + w^399,
    m5*m8 + w^597*m5 + w^466*m6*m9 + w^466*m6 + w^597*m9 + w^597,
    m5*m9 + w^637*m5 + w^415*m6*m9 + w^415*m6 + w^91*m9 + w^91,
    m6*m8 + w^415*m6*m9 + w^142*m6 + w^404*m8 + w^546*m9 + w^182,
    m7 + w^126*m8 + w^450*m9 + w^86
];

// This is equivalent to the single relation a*d*f=1, as it turns out. To prove this we
// need first to eliminate m1,m4,m7 (easy), and then m2, m5 and m8 using the first three relations.

B2c:=[B2[i]:i in [4,12,16]];
coeffs1:=ChangeLinearCoefficients(coeffs0a,B2c);

r1:=[-B2[1]/w^182+m5,-B2[2]/w^404+m8,-B2[3]/w^217+m2];

coeffs1:=ChangeCoefficients(coeffs1,[m5,m8,m2],r1);

// Run Groebner basis again

B3:=GroebnerBasis([Evaluate(i,coeffs1):i in B2]);

// Define a new set of relations. (If these are not correct then the resulting set of coefficients
// would not be only dependent on a,d,f.)
r2:=[-B3[1]/w^51+m6,-B3[2]/w^86+m3,-B3[5]+m9];
coeffs1:=ChangeCoefficients(coeffs1,[m6,m3,m9],r2);

B4:=GroebnerBasis([Evaluate(i,coeffs1):i in B3]);
return B4 eq [a*d*f-1];

// So we obtain the final solution and that there are (q-1)^2 solutions.

end function;

function CheckDetermination()

// Since we may multiply scal by any matrix that centralizes H, we may assume that b=c=e=1. We can then
// multiply by a diagonal element at the end to produce all elements of GL(27,k) that map h1 into G.

coeffs0a:=[a,1,1,d,1,f,m1,m2,m3,m4,m5,m6,m7,m8,m9];

Evaluate(ProdRel([1,1,3]),coeffs0a) eq w^156*(m1+w^35*m2+w^268*m3)*(m1+w^126*m2+w^450*m3)*(1-m1+w^308*m2+w^723*m3);
Evaluate(ProdRel([11,11,12]),coeffs0a) eq w^373*(m4+w^126*m5+w^450*m6)*(m4+w^672*m5+w^359*m6)*(1-m5+w^329*m4+w^597*m6);
Evaluate(ProdRel([20,20,21]),coeffs0a) eq w^60*(m7+w^35*m8+w^268*m9)*(m7+w^672*m8+w^359*m9)*(1-m9+w^642*m7+w^40*m8);

// Deal with the wrong answers for m1 first.
badcoeffs1a:=ChangeCoefficient(coeffs0a,m1,-(w^35*m2+w^268*m3));
badcoeffs1b:=ChangeCoefficient(coeffs0a,m1,-(w^126*m2+w^450*m3));

aa1:=ProdRel([2,2,20]);
Evaluate(aa1,badcoeffs1a) eq w^151*f; //This is impossible
Evaluate(ProdRel([1,2,3]),badcoeffs1b) eq w^44*a*(m2+w^415*m3)^2;
badcoeffs2b:=ChangeCoefficient(badcoeffs1b,m2,-w^415*m3);
Evaluate(aa1,badcoeffs2b) eq w^151*f; // This is again impossible.

// Deal with the wrong answers for m4 next.
badcoeffs1c:=ChangeCoefficient(coeffs0a,m4,-(w^126*m5+w^450*m6));
badcoeffs1d:=ChangeCoefficient(coeffs0a,m4,-(w^672*m5+w^359*m6));

aa2:=ProdRel([1,10,10]);
Evaluate(aa2,badcoeffs1c) eq w^681*a; //This is impossible
Evaluate(ProdRel([10,10,12]),badcoeffs1d) eq w^443*d*(m5+w^233*m6)^2;
badcoeffs2d:=ChangeCoefficient(badcoeffs1d,m5,-w^233*m6);
Evaluate(aa2,badcoeffs2d) eq w^681*a; // This is again impossible.

// Deal with the wrong answers for m7 last.
badcoeffs1e:=ChangeCoefficient(coeffs0a,m7,-(w^672*m8+w^359*m9));
badcoeffs1f:=ChangeCoefficient(coeffs0a,m7,-(w^35*m8+w^268*m9));

aa3:=ProdRel([11,19,19]);
Evaluate(aa3,badcoeffs1e) eq w^727*d; //This is impossible
Evaluate(ProdRel([19,19,21]),badcoeffs1f) eq w^585*f*(m8+w^688*m9)^2;
badcoeffs2f:=ChangeCoefficient(badcoeffs1f,m8,-w^688*m9);
Evaluate(aa3,badcoeffs2f) eq w^727*d; // This is again impossible.

coeffs1:=ChangeCoefficients(coeffs0a,[m1,m5,m9],[1+w^308*m2+w^723*m3,1+w^329*m4+w^597*m6,1+w^642*m7+w^40*m8]);

Evaluate(ProdRel([2,2,12]),coeffs1) eq w^44*(m2+w^688*m3+w^147)*(a+w^91*m2*m4+w^541*m2*m6+w^217*m2+w^324*m3*m4+w^46*m3*m6+w^450*m3+w^597*m6+2);
badcoeffs2g:=ChangeCoefficient(coeffs1,m2,-(w^688*m3+w^147));
Evaluate(aa1,badcoeffs2g) eq w^151*f;

Evaluate(ProdRel([10,10,21]),coeffs1) eq w^186*(m4+w^723*m6+w^581)*(d+w^425*m4*m7+w^369*m4*m8+w^56*m4+w^147*m6*m7+w^91*m6*m8+w^506*m6+w^642*m7+2);
badcoeffs2h:=ChangeCoefficient(coeffs1,m4,-(w^723*m6+w^581));
Evaluate(aa2,badcoeffs2h) eq w^681*a;

Evaluate(ProdRel([3,19,19]),coeffs1) eq w^515*(m7+w^399*m8+w^541)*(f+w^586*m2*m7+w^530*m2*m8+w^308*m2+w^91*m3*m7+w^35*m3*m8+w^551*m7+w^495*m8+2);
badcoeffs2i:=ChangeCoefficient(coeffs1,m7,-(w^399*m8+w^541));
Evaluate(aa3,badcoeffs2i) eq w^727*d;

// We now create three more relations, eliminating m2, m4 and m7.

bb1:=Evaluate(ProdRel([1,3,19]),coeffs1);
bb2:=Factorization(Evaluate(ProdRel([3,19,19]),coeffs1))[2,1];
w^542*bb1-w^693*bb2 eq m2-(w^147*f+w^324*m3+w^511);

bb3:=Evaluate(ProdRel([10,20,21]),coeffs1);
bb4:=Factorization(Evaluate(ProdRel([10,10,21]),coeffs1))[2,1];
w^451*bb3-w^359*bb4 eq m7-(w^541*d+w^35*m8+w^177);

bb5:=Evaluate(ProdRel([2,11,12]),coeffs1);
bb6:=Factorization(Evaluate(ProdRel([2,2,12]),coeffs1))[2,1];
w^173*bb5-w^399*bb6 eq m4-(w^581*a+w^359*m6+w^217);

coeffs2:=ChangeCoefficients(coeffs1,[m2,m4,m7],[w^147*f+w^324*m3+w^511,w^581*a+w^359*m6+w^217,w^541*d+w^35*m8+w^177]);

// Three more coefficients to kill off the remaining three m s.

Evaluate(ProdRel([1,2,12]),coeffs2)/w^277 eq m3-(w^278*a*f+w^96*f+w^369);
Evaluate(ProdRel([10,11,21]),coeffs2)/w^454 eq m6-(w^313*a*d+w^404*a+w^131);
Evaluate(ProdRel([3,19,20]),coeffs2)/w^95 eq m8-(w^233*d*f+w^51*d+w^324);

coeffs3:=ChangeCoefficients(coeffs2,[m3,m6,m8],[w^278*a*f+w^96*f+w^369,w^313*a*d+w^404*a+w^131,w^233*d*f+w^51*d+w^324]);
// Now we can add back in the centralizer of H.

coeffs4:=[b*a,b,c,c*d,e,e*f,b*(2*a*f+f+1),b*(w^602*a*f+w^693*f+w^420),b*(w^278*a*f+w^96*f+w^369),c*(w^672*a*d+w^490*a+w^35),c*(2*a*d+a+1),c*(w^313*a*d+w^404*a+w^131),e*(w^268*d*f+w^359*d+w^86),e*(w^233*d*f+w^51*d+w^324),e*(2*d*f+d+1)];

return true;
end function;

// We now want to know which specializations of scal, the centralizer in GL(27,k) of L, actually lie in G. They
// must satisfy coeffs4, because they conjugate h1 (which lies in G) to something still in G. But we will start
// with scal and apply CheckRel to it to determine the variables.

// We do this directly and with a Groebner basis, as with the previous determination.

function QuickCheckCentralizer()

rels:=[CheckRel(seqs[i],scal):i in [64,73,208,235,397,568,756,761,770,771,904,913,942,1021,2794,2862,3544]];
BB:=GroebnerBasis(rels);

// We don't want to us ChangeLinearCoefficients directly, as before, as we want to specialize the m_i.

coeffs1:=ChangeLinearCoefficients(coeffs0,[BB[i]:i in [7..12]]);

// Now we need to specialize m7,m8,m9.
BB[2] eq b + w^5*m7 + w^677*m8 + 2*m9;
coeffs1:=ChangeCoefficient(coeffs1,m7,-BB[2]/Coefficient(BB[2],m7,1)+m7);
BB:=GroebnerBasis([Evaluate(i,coeffs1):i in rels]);
BB[2] eq b + w^455*e + w^404*m8 + w^637*m9;
coeffs1:=ChangeCoefficient(coeffs1,m8,-BB[2]/Coefficient(BB[2],m8,1)+m8);
BB:=GroebnerBasis([Evaluate(i,coeffs1):i in rels]);
BB[2] eq b + 2*c + e + 2*m9;
coeffs1:=ChangeCoefficient(coeffs1,m9,-BB[2]/Coefficient(BB[2],m9,1)+m9);
BB:=GroebnerBasis([Evaluate(i,coeffs1):i in rels]);
return BB eq [
    a + 2*b^2*e^2,
    b*c + 2*d*e,
    b*f + 2*c*e,
    c^2 + 2*d*f,
    d*e^2 + 2
];

// This proves that there are (q-1)^2 options as well. First, d,e ne 0 by eq. 5, then b,c ne 0 by eq 2.
// Choose b and e arbitrarily. Then: a is fixed from eq. 1. d is fixed from eq 5. c from eq. 2, and f
// from eq. 3.

// We have used all but equation 4 and determined all solutions, so we should check that 4 follows from
// the others. But:

// df=d(ce/b) (eq. 3)
//   =de(d/b)=bc(c/b) (eq. 2)
//   =c^2.

// So we do not need this equation, and the result holds.

end function;


function CheckCentralizer()

[CheckRel(seqs[i],scal):i in [208,235,397,568,2794]] eq [w^317*a*c^2+w^681,w^277*a*d*f+w^641,w^515*b^2*f+w^151,w^95*b*c*e+w^459,w^363*d*e^2+w^727];
//Thus ac^2=b^2f=de^2=adf=bce=1.


CheckRel(seqs[771],scal)/-w^658 eq f*(m1+w^672*m2+w^359*m3)^2-1;
CheckRel(seqs[2862],scal)/-w^546 eq f*(w^56*m4+m5+w^415*m6)^2-1;
CheckRel(seqs[3544],scal)/-w^648 eq f*(w^369*m7+w^313*m8+m9)^2-1;

// We will deal with determining m1,m2,m3 first. The others are similar. We first use the other equations with seven monomials,
// and the relations with a,...,f above, to yield two more relationships with 

// Since fb^2=1 as well, we see that b=\pm (m1+w^672m2+w^359m3)=\pm(w^56*m4+m5+w^415*m6)=\pm(w^369*m7+w^313*m8+m9)
// Assume that b=-m1-w^672*m2-w^359*m3), so m1=-b-w^672*m2-w^359*m3

CheckRel(seqs[770],scal)/-w^190 eq e*(m1+w^35*m2+w^268*m3)*(m1+w^672*m2+w^359*m3)-1;
CheckRel(seqs[761],scal)/-w^87 eq c*(m1 + w^126*m2 + w^450*m3)*(m1 + w^672*m2 + w^359*m3)-1;

// Combine these with b=-(m1+w^672*m2+w^359*m3) and b*c*e=1, and we obtain three simultaneous equations, which allow us to write all
// of m1,m2,m3 in terms of b,c,e.

// m1=-b-w^672*m2-w^359*m3
// c=-(m1+w^35*m2+w^268*m3)=-(-b-w^672*m2-w^359*m3+w^35*m2+w^268*m3)=b+w^217*m2+w^177*m3, so
// m2=w^147*b+w^511*c+w^324*m3, m1=-b-w^672*(w^147*b+w^511*c+w^324*m3)-w^359*m3=w^546*b+w^91*c+w^86*m3
// e=-(m1 + w^126*m2 + w^450*m3)=-((w^546*b+w^91*c+w^86*m3)+w^126*(w^147*b+w^511*c+w^324*m3)+w^450*m3)=w^455*b + w^182*c + w^86*m3
// m3=w^5*b+w^460*c+w^642*e, m2=w^56*b + w^329*c + w^238*e,m1=2*b + 2*c + e.

bc1a:=[a,b,c,d,e,f,2*b + 2*c + e,w^56*b + w^329*c + w^238*e,w^5*b+w^460*c+w^642*e,m4,m5,m6,m7,m8,m9];

// This now yields a contradiction:

Evaluate(CheckRel([3,4,5],scal),bc1a)/w^338 eq b*c*e+1; // But we already know b*c*e+2.

// So b=m1+w^672*m2+w^359*m3, c=m1+w^35*m2+w^268*m3, e=m1 + w^126*m2 + w^450*m3.
// As above, we can use these to evaluate m1,m2,m3 in terms of b,c,e.
// (Just invert the appropriate matrix.)
// m1=b+c-e
// m2=w^420*b+w^693*c+w^602*e
// m3=w^369*b+w^96*c+w^278*e

c1:=[a,b,c,d,e,f,b+c-e,w^420*b+w^693*c+w^602*e,w^369*b+w^96*c+w^278*e,m4,m5,m6,m7,m8,m9];

// Now we use these to determine m4,m5,m6.

Evaluate(CheckRel([1,3,13],scal),c1)/-w^35 eq a*c*(w^693*m4+m5+w^233*m6)-1;
Evaluate(CheckRel([3,11,13],scal),c1)/-w^694 eq d*e*(w^602*m4+m5+w^324*m6)-1;
Evaluate(CheckRel([3,13,20],scal),c1)/-w^602 eq b*f*(w^56*m4+m5+w^415*m6)-1;

// Thus we have b=w^56*m4+m5+w^415*m6, c=w^693*m4+m5+w^233*m6, e=w^602*m4+m5+w^324*m6

// Hence
// m4=w^672*b+w^35*c+w^490*e
// m5=-b+c+e
// m6=w^313*b+w^131*c+w^404*e

Evaluate(CheckRel([1,3,22],scal),c1)/-w^268 eq a*c*(w^460*m7+w^495*m8+m9)-1;
Evaluate(CheckRel([3,11,22],scal),c1)/-w^290 eq d*e*(w^278*m7+w^404*m8+m9)-1;
Evaluate(CheckRel([3,20,22],scal),c1)/-w^289 eq b*f*(w^369*m7+w^313*m8+m9)-1;

// Thus we have b=w^369*m7+w^313*m8+m9, c=w^460*m7+w^495*m8+m9, e=w^278*m7+w^404*m8+m9

// Hence
// m7=w^359*b+w^268*c+w^86*e
// m8=w^51*b+w^233*c+w^324*e
// m9=b-c+e

c2:=[a,b,c,d,e,f,b+c-e,w^420*b+w^693*c+w^602*e,w^369*b+w^96*c+w^278*e,w^672*b+w^35*c+w^490*e,-b+c+e,w^313*b+w^131*c+w^404*e,w^359*b+w^268*c+w^86*e,w^51*b+w^233*c+w^324*e,b-c+e];

// All relations now collapse to the five we have above, ac^2=b^2f=de^2=adf=bce=1. Of course, the last follows from the previous four.
// This yields (q-1)^2 solutions, as claimed.

// Now we check that c2 is a special case of coeffs4 above.

coeffs4:=[b*a,b,c,c*d,e,e*f,b*(2*a*f+f+1),b*(w^602*a*f+w^693*f+w^420),b*(w^278*a*f+w^96*f+w^369),c*(w^672*a*d+w^490*a+w^35),c*(2*a*d+a+1),c*(w^313*a*d+w^404*a+w^131),e*(w^268*d*f+w^359*d+w^86),e*(w^233*d*f+w^51*d+w^324),e*(2*d*f+d+1)];

// Recall that adf=1 in coeffs4, and in c2 we have ac^2=b^2f=de^2=adf=bce=1.
// We first perform a change of variables, which of course does not affect the structure of the centralizer as all of a..f are non-zero.

c2a:=[Evaluate(i,[a*b,b,c,c*d,e,e*f,0,0,0,0,0,0,0,0,0]):i in c2];
// Our equations for c2a are now abc^2=b^2ef=cde^2=abcdef=bce=1

c2a eq [
    a*b,
    b,
    c,
    c*d,
    e,
    e*f,
    b + c + 2*e,
    w^420*b + w^693*c + w^602*e,
    w^369*b + w^96*c + w^278*e,
    w^672*b + w^35*c + w^490*e,
    2*b + c + e,
    w^313*b + w^131*c + w^404*e,
    w^359*b + w^268*c + w^86*e,
    w^51*b + w^233*c + w^324*e,
    b + 2*c + e
];

coeffs4 eq [
    a*b,
    b,
    c,
    c*d,
    e,
    e*f,
    2*a*b*f + b*f + b,
    w^602*a*b*f + w^693*b*f + w^420*b,
    w^278*a*b*f + w^96*b*f + w^369*b,
    w^672*a*c*d + w^490*a*c + w^35*c,
    2*a*c*d + a*c + c,
    w^313*a*c*d + w^404*a*c + w^131*c,
    w^268*d*e*f + w^359*d*e + w^86*e,
    w^233*d*e*f + w^51*d*e + w^324*e,
    2*d*e*f + d*e + e
];

// These look different, but applications of our relations can alter the first equations to look like the second:
// abc^2=b^2ef=cde^2=abcdef=bce=1 yield:
// b=acd=de, c=bf=def, e=abf=ac.
// With these equivalences, the first set of equations becomes the second.

// Now we note that the matrices specified by coeffs4 are the product of the centralizer of H by those given by c2a.
// For this, we first have that those given by c2a are a subset (both satisfy adf=1), as seen above, and the
// centralizer of H is given by setting a=d=f=1. Since they are both subgroups, and intersect trivially, and the
// orders over every finite field coincide, we see that the result holds.

return true;
end function;

function CheckE6Form()

qq:=9;
FF<ww>:=GF(qq);
GG:=GroupOfLieType("E6",qq);
a1:=1; a2:=-ww;
y1:=elt<GG|<1,1>>*elt<GG|<3,1>>*elt<GG|<7,1>>*elt<GG|<2,1>>*elt<GG|<5,1>>
 *elt<GG|<6,1>>*elt<GG|<11,1>>;
y2:=elt<GG|<1+36,2>>*elt<GG|<3+36,2>>*elt<GG|<7+36,2>>*elt<GG|<2+36,1>>
 *elt<GG|<5+36,2>>*elt<GG|<6+36,2>>*elt<GG|<11+36,2>>;
y3:=elt<GG|<9,1>>*elt<GG|<8,a2>>*elt<GG|<10,a1+a2/2>>;
y4:=elt<GG|<9+36,1>>*elt<GG|<8+36,1/a2>>*elt<GG|<10+36,(1+a2/2)^-1>>;

Over:=GL(27,qq);
rho:=StandardRepresentation(GG);
HH:=sub<Over|[rho(i):i in [y1,y2,y3,y4]]>;

Over!(l1^x) in HH and Over!(l2^x) in HH;

mat:=[];
for h in [l1,l2,h1] do
  for nn in [1..#seqs] do aa:=seqs[nn,1]; bb:=seqs[nn,2]; cc:=seqs[nn,3];
    val:=[F!0:i in [1..#seqs]];
    for i in [1..NumberOfRows(h)] do if(h[aa,i] ne 0) then for j in [1..NumberOfRows(h)] do if(h[bb,j] ne 0) then for k in [1..NumberOfRows(h)] do
      val[Position(seqs,Sort([i,j,k]))]+:=h[aa,i]*h[bb,j]*h[cc,k];
    end for; end if; end for; end if; end for;
    val[nn]-:=1; Append(~mat,val); delete val;
  end for;
end for;

g:=Random(GG);
h:=x*GL(27,F)!rho(g)*x^-1;
repeat
  nn:=Random([1..#seqs]); aa:=seqs[nn,1]; bb:=seqs[nn,2]; cc:=seqs[nn,3];
    val:=[F!0:i in [1..#seqs]];
    for i in [1..NumberOfRows(h)] do if(h[aa,i] ne 0) then for j in [1..NumberOfRows(h)] do if(h[bb,j] ne 0) then for k in [1..NumberOfRows(h)] do
      val[Position(seqs,Sort([i,j,k]))]+:=h[aa,i]*h[bb,j]*h[cc,k];
    end for; end if; end for; end if; end for;
  val[nn]-:=1; Append(~mat,val); delete val;
  Nu:=Nullspace(Transpose(Matrix(F,mat)));
until Dimension(Nu) eq 1;
ftest:=Nu.1;
return &and[ftest[i] eq f27[i]:i in [1..#seqs]];
end function;

"The function CheckE6Form() checks that the trilinear form f27 from E6 is correct. (This takes about 20 minutes.)";
printf "\n";
"The function QuickCheckDetermination() checks that the determination of the possible conjugates into E6 is correct using Groebner bases. (This takes about five minutes.)";
printf "\n";
"The function CheckDetermination() checks that the determination of the possible conjugates into E6 is correct. (This takes about a minute.)";
printf "\n";
"The function QuickCheckCentralizer() checks that there are exactly (q-1)^2 possibilities for a centralizing element of L in GL(27,F) to lie in E6 using Groebner bases. (This takes about a minute.)";
printf "\n";
"The function CheckCentralizer() checks that there are exactly (q-1)^2 possibilities for a centralizing element of L in GL(27,F) to lie in E6. It shows this directly, and shows that they are equal to the solutions obtained via CheckDetermination(). (This takes about a minute.)";