load "Subgroups/functions.txt";

function FindOrb(Orbs,i)
for Orb in Orbs do if(i in Orb) then return Orb; end if; end for;
return {};
end function;

q:=2^12;
m:=q-1;
F<w2>:=GF(q);
//n:=(q-1) div m;
G:=GroupOfLieType("E8",q);
V:=VectorSpace(GF(q),8);
rho1:=StandardRepresentation(G);
Over1:=GL(248,q);
g1:=elt<G|V![w2,1,1,1,1,1,1,1]>;
g2:=elt<G|V![1,w2,1,1,1,1,1,1]>;
g3:=elt<G|V![1,1,w2,1,1,1,1,1]>;
g4:=elt<G|V![1,1,1,w2,1,1,1,1]>;
g5:=elt<G|V![1,1,1,1,w2,1,1,1]>;
g6:=elt<G|V![1,1,1,1,1,w2,1,1]>;
g7:=elt<G|V![1,1,1,1,1,1,w2,1]>;
g8:=elt<G|V![1,1,1,1,1,1,1,w2]>;
W:=Reflections(G);
Mats1:=[rho1(i):i in [g1,g2,g3,g4,g5,g6,g7,g8]];
MatsE:=[rho1(i):i in W];
NGT:=sub<Over1|Mats1 cat MatsE>;
T:=sub<NGT|Mats1>;
E:=sub<NGT|MatsE>;
T315:=sub<T|[T.i^13:i in [1..8]]>;

R:=ResidueClassRing(315);
X:=[[R!(Log((T315.j)[i,i]) div 13):i in [1..248]]:j in [1..8]];

Eigs11:={ <w2^2470, 1>, <w2^2522, 1>, <w2^2951, 1>, <w2^403, 1>, <w2^2275, 1>, <w2^2860, 2>,<w2^2938, 1>, <w2^3848, 1>, <w2^390, 3>, <w2^468, 1>, <w2^2925, 1>, <w2^559, 2>, <w2^1755,
1>, <w2^3523, 1>, <w2^598, 1>, <w2^3549, 1>, <w2^4017, 2>, <w2^3029, 3>, <w2^2223, 1>,<w2^481, 1>, <w2^2457, 3>, <w2^3250, 2>, <w2^2873, 1>, <w2^1287, 1>, <w2^3562, 1>,
<w2^1105, 1>, <w2^793, 1>, <w2^702, 1>, <w2^3198, 2>, <w2^1612, 1>, <w2^1157, 1>, <w2^1898,1>, <w2^546, 1>, <w2^988, 1>, <w2^1430, 1>, <w2^1742, 1>, <w2^2808, 1>, <w2^3926, 3>,
<w2^533, 1>, <1, 8>, <w2^1222, 1>, <w2^2288, 1>, <w2^2665, 1>, <w2^3185, 1>, <w2^780, 1>,<w2^975, 1>, <w2^3172, 1>, <w2^221, 2>, <w2^3302, 1>, <w2^1703, 1>, <w2^3900, 1>, <w2^3107,
1>, <w2^3874, 2>, <w2^2132, 1>, <w2^4004, 1>, <w2^1053, 1>, <w2^1300, 1>, <w2^3588, 2>,<w2^1859, 2>, <w2^1456, 1>, <w2^169, 3>, <w2^1963, 1>, <w2^2405, 1>, <w2^3341, 2>,
<w2^3419, 3>, <w2^3978, 1>, <w2^2353, 1>, <w2^1638, 3>, <w2^3640, 1>, <w2^1274, 1>,<w2^1781, 3>, <w2^195, 1>, <w2^1248, 2>, <w2^3731, 1>, <w2^3809, 1>, <w2^3380, 2>, <w2^78,
2>, <w2^1924, 1>, <w2^3601, 1>, <w2^1352, 1>, <w2^2067, 2>, <w2^3692, 1>, <w2^845, 2>,<w2^1690, 1>, <w2^572, 1>, <w2^1950, 3>, <w2^3393, 1>, <w2^676, 3>, <w2^910, 1>, <w2^3211,
2>, <w2^2392, 1>, <w2^312, 2>, <w2^2990, 1>, <w2^3614, 1>, <w2^1820, 1>, <w2^117, 1>,<w2^3276, 1>, <w2^247, 1>, <w2^2821, 1>, <w2^3536, 2>, <w2^3770, 1>, <w2^1560, 3>,
<w2^2639, 1>, <w2^3497, 1>, <w2^2743, 1>, <w2^507, 2>, <w2^1573, 1>, <w2^1976, 1>,<w2^2197, 1>, <w2^1729, 1>, <w2^2535, 3>, <w2^1391, 3>, <w2^1066, 3>, <w2^2795, 1>,
<w2^585, 1>, <w2^1079, 2>, <w2^325, 1>, <w2^286, 1>, <w2^754, 2>, <w2^1001, 1>, <w2^1144,1>, <w2^897, 2>, <w2^1807, 1>, <w2^2236, 2>, <w2^3315, 1>, <w2^1417, 1>, <w2^3133, 1>,
<w2^1625, 1>, <w2^3757, 1>, <w2^3705, 3>, <w2^494, 1>, <w2^338, 1>, <w2^1170, 1>, <w2^3952,1>, <w2^923, 1>, <w2^455, 1>, <w2^1235, 2>, <w2^1872, 1>, <w2^364, 1>, <w2^2704, 3>,
<w2^3627, 1>, <w2^3120, 1>, <w2^1313, 1>, <w2^3510, 1>, <w2^2145, 3>, <w2^2717, 1>,<w2^3042, 1>, <w2^2340, 1>, <w2^2314, 3>, <w2^143, 1>, <w2^715, 2>, <w2^3783, 2>, <w2^2782,
1>, <w2^1911, 1>, <w2^2184, 1>, <w2^3094, 1>, <w2^2028, 2>, <w2^1378, 1>, <w2^3016, 2>,<w2^2366, 1>, <w2^2847, 2>, <w2^91, 1>, <w2^884, 2>, <w2^2678, 1>, <w2^819, 1>, <w2^2171,
1>, <w2^2483, 1>, <w2^962, 1>, <w2^2119, 1>, <w2^2626, 3>, <w2^1469, 3> };

Eigs12:={ <w2^858, 3>, <w2^975, 2>, <w2^819, 3>, <w2^3744, 3>, <w2^3666, 2>, <w2^273, 3>, <w2^2028,3>, <w2^1521, 3>, <1, 8>, <w2^2535, 2>, <w2^1482, 3>, <w2^585, 5>, <w2^2496, 2>, <w2^897,3>, <w2^4017, 3>, <w2^936, 3>, <w2^1092, 3>, <w2^1950, 2>, <w2^2691, 3>, <w2^2106, 3>,<w2^234, 3>, <w2^3900, 2>, <w2^1248, 3>, <w2^3276, 3>, <w2^1209, 2>, <w2^3588, 3>,
<w2^2730, 3>, <w2^1365, 3>, <w2^2262, 3>, <w2^3861, 3>, <w2^2652, 3>, <w2^2574, 3>,<w2^3783, 3>, <w2^663, 3>, <w2^1716, 2>, <w2^4056, 2>, <w2^2301, 2>, <w2^156, 2>, <w2^1989,
3>, <w2^2067, 3>, <w2^3354, 2>, <w2^39, 2>, <w2^2457, 3>, <w2^1014, 2>, <w2^3159, 3>,<w2^78, 3>, <w2^1404, 3>, <w2^1755, 5>, <w2^3432, 3>, <w2^2418, 3>, <w2^1131, 2>, <w2^2964,
2>, <w2^1326, 2>, <w2^312, 3>, <w2^2340, 5>, <w2^2379, 2>, <w2^390, 2>, <w2^1170, 5>,<w2^3081, 2>, <w2^3705, 2>, <w2^780, 2>, <w2^1833, 3>, <w2^3315, 2>, <w2^2145, 2>,
<w2^3003, 3>, <w2^624, 2>, <w2^3237, 3>, <w2^2769, 2>, <w2^741, 2>, <w2^2613, 3>, <w2^3939,2>, <w2^429, 2>, <w2^1599, 2>, <w2^3510, 5>, <w2^2925, 5>, <w2^1560, 2>, <w2^2886, 2>,
<w2^1794, 2>, <w2^3198, 3>, <w2^1443, 3>, <w2^1677, 3>, <w2^195, 2>, <w2^3120, 2>,<w2^3822, 3>, <w2^507, 3>, <w2^1638, 3>, <w2^3471, 2>, <w2^2847, 3>, <w2^351, 3> };

Eigs13:={ <w2^936, 6>, <w2^1755, 9>, <w2^2925, 9>, <w2^117, 7>, <w2^3510, 9>, <w2^585, 9>,<w2^1638, 3>, <w2^3861, 6>, <w2^3627, 7>, <w2^2223, 7>, <w2^2106, 6>, <w2^819, 9>,
<w2^1521, 6>, <w2^3978, 7>, <w2^2457, 3>, <w2^2691, 6>, <w2^3744, 6>, <w2^468, 7>,<w2^2340, 9>, <w2^351, 6>, <w2^2574, 6>, <w2^3276, 9>, <w2^3042, 7>, <w2^1053, 7>,
<w2^1872, 7>, <w2^234, 6>, <w2^1170, 9>, <1, 14>, <w2^1404, 6>, <w2^702, 7>, <w2^3159, 6>,<w2^3393, 7>, <w2^1989, 6>, <w2^1287, 7>, <w2^2808, 7> };

Eigs14:={ <w2^1755, 35>, <w2^585, 35>, <w2^2925, 35>, <1, 38>, <w2^2340, 35>, <w2^3510, 35>, <w2^1170, 35> };

Eigs21:={ <w2^3536, 1>, <w2^52, 3>, <w2^832, 3>, <w2^2951, 1>, <w2^286, 1>, <w2^1638, 2>, <w2^3120,2>, <1, 8>, <w2^3497, 1>, <w2^1560, 1>, <w2^3887, 3>, <w2^4030, 4>, <w2^1950, 1>, <w2^767,3>, <w2^3328, 3>, <w2^4082, 3>, <w2^3874, 1>, <w2^3107, 1>, <w2^3705, 1>, <w2^715, 1>,<w2^1807, 1>, <w2^3341, 1>, <w2^1105, 3>, <w2^481, 1>, <w2^1313, 2>, <w2^117, 1>, <w2^1859,
1>, <w2^221, 1>, <w2^3263, 3>, <w2^3523, 1>, <w2^1248, 1>, <w2^1690, 1>, <w2^143, 1>,<w2^533, 2>, <w2^3900, 2>, <w2^4043, 3>, <w2^247, 1>, <w2^3393, 1>, <w2^3276, 2>, <w2^2782,
2>, <w2^1703, 1>, <w2^3068, 3>, <w2^1430, 1>, <w2^78, 1>, <w2^2145, 1>, <w2^3822, 4>,<w2^1417, 1>, <w2^585, 1>, <w2^338, 2>, <w2^1963, 2>, <w2^1235, 1>, <w2^2808, 1>, <w2^2535,
1>, <w2^884, 1>, <w2^572, 1>, <w2^819, 2>, <w2^3315, 2>, <w2^2847, 1>, <w2^780, 2>,<w2^975, 2>, <w2^468, 1>, <w2^3614, 1>, <w2^2288, 1>, <w2^2236, 1>, <w2^2470, 1>, <w2^260,
4>, <w2^2522, 1>, <w2^897, 1>, <w2^4017, 1>, <w2^325, 3>, <w2^3770, 3>, <w2^3198, 1>,<w2^2730, 3>, <w2^1872, 1>, <w2^3380, 1>, <w2^2223, 1>, <w2^3510, 1>, <w2^390, 1>,
<w2^1079, 1>, <w2^3952, 1>, <w2^1040, 4>, <w2^1365, 3>, <w2^1053, 1>, <w2^3133, 1>,<w2^1352, 2>, <w2^2340, 1>, <w2^208, 3>, <w2^988, 1>, <w2^2743, 2>, <w2^1898, 1>, <w2^2457,
2>, <w2^3809, 1>, <w2^2860, 1>, <w2^2067, 1>, <w2^3562, 2>, <w2^2717, 1>, <w2^2678, 1>,<w2^1300, 3>, <w2^3211, 1>, <w2^3250, 1>, <w2^3042, 1>, <w2^2171, 1>, <w2^2665, 1>,
<w2^2028, 1>, <w2^3757, 2>, <w2^1170, 1>, <w2^3003, 4>, <w2^2392, 1>, <w2^702, 1>,<w2^3848, 1>, <w2^3835, 4>, <w2^1027, 3>, <w2^3627, 1>, <w2^13, 3>, <w2^845, 1>, <w2^1924,
1>, <w2^3783, 1>, <w2^3588, 1>, <w2^3978, 1>, <w2^1625, 1>, <w2^1755, 1>, <w2^1092, 4>,<w2^754, 1>, <w2^2925, 1>, <w2^195, 2>, <w2^2132, 2>, <w2^1573, 1>, <w2^2990, 3>, <w2^598,
1>, <w2^2938, 2>, <w2^507, 1>, <w2^1144, 1>, <w2^559, 1>, <w2^2405, 1>, <w2^2795, 3>,<w2^1976, 1>, <w2^2197, 1>, <w2^962, 1>, <w2^1287, 1>, <w2^1378, 1>, <w2^3016, 1>,
<w2^2119, 1>, <w2^494, 1>, <w2^273, 4>, <w2^1157, 2>, <w2^312, 1>, <w2^3055, 4>, <w2^3601,1>, <w2^65, 4> };

Eigs22:={ <1, 14>, <w2^3081, 6>, <w2^1794, 6>, <w2^1209, 1>, <w2^585, 4>, <w2^3861, 2>, <w2^1599,6>, <w2^2496, 6>, <w2^2340, 4>, <w2^2925, 4>, <w2^2964, 1>, <w2^156, 6>, <w2^195, 8>,
<w2^1404, 2>, <w2^1833, 2>, <w2^234, 2>, <w2^2574, 2>, <w2^2652, 2>, <w2^3354, 1>,<w2^2301, 6>, <w2^1950, 1>, <w2^2769, 1>, <w2^975, 8>, <w2^2613, 2>, <w2^2457, 2>,
<w2^2145, 1>, <w2^2691, 2>, <w2^3510, 4>, <w2^819, 10>, <w2^1989, 2>, <w2^2106, 2>,<w2^858, 2>, <w2^2418, 2>, <w2^2535, 1>, <w2^3705, 1>, <w2^936, 2>, <w2^2379, 1>, <w2^1014,
6>, <w2^3315, 8>, <w2^1170, 4>, <w2^3237, 2>, <w2^1482, 2>, <w2^3744, 2>, <w2^1131, 1>,<w2^3666, 1>, <w2^1716, 1>, <w2^3120, 8>, <w2^4056, 6>, <w2^1521, 2>, <w2^1443, 2>,
<w2^1677, 2>, <w2^1755, 4>, <w2^663, 2>, <w2^2886, 1>, <w2^390, 1>, <w2^1560, 1>, <w2^741,1>, <w2^624, 6>, <w2^3939, 6>, <w2^3276, 10>, <w2^429, 1>, <w2^2262, 2>, <w2^780, 8>,
<w2^39, 6>, <w2^351, 2>, <w2^1326, 1>, <w2^3159, 2>, <w2^3471, 6>, <w2^1638, 2>, <w2^3900,8>, <w2^3432, 2> };

Eigs23:={ <w2^117, 9>, <w2^936, 2>, <w2^3159, 2>, <w2^3393, 9>, <w2^2223, 9>, <w2^1989, 2>,<w2^3744, 2>, <w2^3861, 2>, <w2^1521, 2>, <w2^1053, 9>, <w2^2340, 13>, <w2^702, 9>,
<w2^2457, 10>, <w2^351, 2>, <w2^468, 9>, <w2^2106, 2>, <w2^3510, 13>, <w2^585, 13>,<w2^2691, 2>, <w2^1287, 9>, <1, 14>, <w2^1755, 13>, <w2^3978, 9>, <w2^1638, 10>, <w2^2925,
13>, <w2^3276, 2>, <w2^1872, 9>, <w2^2574, 2>, <w2^2808, 9>, <w2^234, 2>, <w2^819, 2>,<w2^1170, 13>, <w2^3627, 9>, <w2^3042, 9>, <w2^1404, 2> };

Eigs24:={ <w2^1755, 35>, <w2^585, 35>, <w2^2925, 35>, <1, 38>, <w2^2340, 35>, <w2^3510, 35>,<w2^1170, 35> };


//This is the case for Eigs11 to Eigs14

El1:=[180,270,45,225,225,225,90,0];
Els1:=ConstructPreimages(El1,315,5);

NextEls1:=[];
e22:={*i[1]^^i[2]:i in Eigs13*};
e2:={*R!(Log(i) div 13):i in e22*};
for ii in [1..#Els1] do
  if e2 eq {*&+[Els1[ii,i]*X[i,j]:i in [1..8]]:j in [1..248]*} then Append(~NextEls1,Els1[ii]); end if;
end for;

gg1:=ProduceGroupElements(T315,NextEls1);
EltsToMerge:=[E.1*E.2*E.3*E.4*E.5*E.4*E.2*E.3*E.4*E.5*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.7*E.6*E.5*E.4*E.8*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.1*E.7*E.6*E.5*E.4*E.2*E.8*E.7*E.6*E.5,
E.1*E.4*E.2*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.8*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.1*E.7*E.6*E.5*E.8*E.7,
E.1*E.3*E.4*E.2*E.3*E.4*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.7*E.8*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.1*E.7*E.6];

Orbs:={{i}:i in [1..#NextEls1]};
for e in EltsToMerge do
  for i in [1..#NextEls1] do
    j:=Position(gg1,gg1[i]^e);
    Orb1:=FindOrb(Orbs,i);
    if(j ne 0 and not(j in Orb1)) then
      Orb2:=FindOrb(Orbs,j);
      Exclude(~Orbs,Orb1);
      Exclude(~Orbs,Orb2);
      Include(~Orbs,Orb1 join Orb2); //printf "Merged %o and %o.\n",Orb1,Orb2;
      delete Orb1; delete Orb2; if(#Orbs eq 1) then "All merged"; break e; end if;
    end if;
  end for;
  "So far we have merged elements into",#Orbs,"orbits";
end for;


El2:=NextEls1[1];
Els2:=ConstructPreimages(El2,315,3);

NextEls2:=[];
e32:={*i[1]^^i[2]:i in Eigs12*};
e3:={*R!(Log(i) div 13):i in e32*};
for ii in [1..#Els2] do
  if e3 eq {*&+[Els2[ii,i]*X[i,j]:i in [1..8]]:j in [1..248]*} then Append(~NextEls2,Els2[ii]); end if;
end for;

EltsToMerge:=[E.1*E.2*E.3*E.4*E.5*E.4*E.2*E.3*E.1,E.8,
E.1*E.3*E.4*E.2*E.6*E.5*E.4*E.3*E.1*E.7*E.6*E.5*E.4*E.2*E.3*E.4*E.5*E.6*E.7*E.8*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.1*E.7*E.6];

gg2:=ProduceGroupElements(T315,NextEls2);
Orbs:={{i}:i in [1..#NextEls2]};
for e in EltsToMerge do
  for i in [1..#NextEls2] do
    j:=Position(gg2,gg2[i]^e);
    Orb1:=FindOrb(Orbs,i);
    if(j ne 0 and not(j in Orb1)) then
      Orb2:=FindOrb(Orbs,j);
      Exclude(~Orbs,Orb1);
      Exclude(~Orbs,Orb2);
      Include(~Orbs,Orb1 join Orb2); //printf "Merged %o and %o.\n",Orb1,Orb2;
      delete Orb1; delete Orb2; if(#Orbs eq 1) then "All merged"; break e; end if;
    end if;
  end for;
  "So far we have merged elements into",#Orbs,"orbits";
end for;

El3:=NextEls2[1];
Els3:=ConstructPreimages(El3,315,3);

NextEls3:=[];
e42:={*i[1]^^i[2]:i in Eigs11*};
e4:={*R!(Log(i) div 13):i in e42*};
for ii in [1..#Els3] do
  if e4 eq {*&+[Els3[ii,i]*X[i,j]:i in [1..8]]:j in [1..248]*} then Append(~NextEls3,Els3[ii]); end if;
end for;

NextEls3 eq [[ 165, 272, 246, 208, 124, 215, 107, 140 ]];


//This is the case for Eigs21 to Eigs24

El1:=[0,180,90,90,180,180,0,135];
Els1:=ConstructPreimages(El1,315,5);

NextEls1:=[];
e22:={*i[1]^^i[2]:i in Eigs23*};
e2:={*R!(Log(i) div 13):i in e22*};
for ii in [1..#Els1] do
  if e2 eq {*&+[Els1[ii,i]*X[i,j]:i in [1..8]]:j in [1..248]*} then Append(~NextEls1,Els1[ii]); end if;
end for;

gg1:=ProduceGroupElements(T315,NextEls1);
EltsToMerge:=[E.1*E.3*E.4*E.2*E.3*E.1*E.4*E.3*E.6*E.5*E.4*E.2*E.3*E.1*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.8*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.1*E.7*E.6*E.5*E.4*E.2*E.3*E.4*E.8*E.7*E.6,E.3*E.4*E.2*E.3*E.4*E.5*E.4*E.3*E.6*E.5*E.4*E.3*E.1*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.5*E.6*E.7*E.8*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.1*E.7*E.6,E.3*E.4*E.2*E.5*E.4*E.3*E.1*E.6*E.5*E.4*E.2*E.3*E.4*E.5*E.6*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3,E.1*E.2*E.3*E.1*E.4*E.2*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.6*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.7*E.8*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4];

Orbs:={{i}:i in [1..#NextEls1]};
for e in EltsToMerge do
  for i in [1..#NextEls1] do
    j:=Position(gg1,gg1[i]^e);
    Orb1:=FindOrb(Orbs,i);
    if(j ne 0 and not(j in Orb1)) then
      Orb2:=FindOrb(Orbs,j);
      Exclude(~Orbs,Orb1);
      Exclude(~Orbs,Orb2);
      Include(~Orbs,Orb1 join Orb2); //printf "Merged %o and %o.\n",Orb1,Orb2;
      delete Orb1; delete Orb2; if(#Orbs eq 1) then "All merged"; break e; end if;
    end if;
  end for;
  "So far we have merged elements into",#Orbs,"orbits";
end for;

El2:=NextEls1[1];
Els2:=ConstructPreimages(El2,315,3);

NextEls2:=[];
e32:={*i[1]^^i[2]:i in Eigs22*};
e3:={*R!(Log(i) div 13):i in e32*};
for ii in [1..#Els2] do
  if e3 eq {*&+[Els2[ii,i]*X[i,j]:i in [1..8]]:j in [1..248]*} then Append(~NextEls2,Els2[ii]); end if;
end for;

NextEls2 eq [[ 252, 285, 48, 27, 243, 12, 126, 114 ]];

El3:=NextEls2[1];
Els3:=ConstructPreimages(El3,315,3);

NextEls3:=[];
e42:={*i[1]^^i[2]:i in Eigs21*};
e4:={*R!(Log(i) div 13):i in e42*};
for ii in [1..#Els3] do
  if e4 eq {*&+[Els3[ii,i]*X[i,j]:i in [1..8]]:j in [1..248]*} then Append(~NextEls3,Els3[ii]); end if;
end for;

gg3:=ProduceGroupElements(T315,NextEls3);
EltsToMerge:=[E.3*E.1*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.3*E.1*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.7*E.6*E.5*E.4*E.2*E.8*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.7*E.6,E.1*E.3*E.4*E.2*E.5*E.4*E.3*E.1*E.6*E.5*E.4*E.2*E.3*E.4*E.5*E.6*E.7*E.6*E.5*E.4*E.2*E.3*E.1*E.4*E.3*E.5*E.4*E.2*E.6*E.5*E.4*E.3*E.1,E.4*E.2*E.3*E.4*E.5*E.4*E.2*E.3*E.4];
Orbs:={{i}:i in [1..#NextEls3]};
for e in EltsToMerge do
  for i in [1..#NextEls3] do
    j:=Position(gg3,gg3[i]^e);
    Orb1:=FindOrb(Orbs,i);
    if(j ne 0 and not(j in Orb1)) then
      Orb2:=FindOrb(Orbs,j);
      Exclude(~Orbs,Orb1);
      Exclude(~Orbs,Orb2);
      Include(~Orbs,Orb1 join Orb2); //printf "Merged %o and %o.\n",Orb1,Orb2;
      delete Orb1; delete Orb2; if(#Orbs eq 1) then "All merged"; break e; end if;
    end if;
  end for;
  "So far we have merged elements into",#Orbs,"orbits";
end for;

"The conjugacy classes for the two elements of order 315 are unique.";
