function XXXFindTwistInLowWeight(f, N)
   ell := Characteristic(BaseRing(Parent(f)));
   assert N mod ell ne 0;
   prec := AbsolutePrecision(f);
   pow := Order(IntegerRing(EulerPhi(N))!ell);  // ord divides ell^pow - 1 
   F<alp> := GF(ell^pow);
   G := DirichletGroup(N,F);

  /* This implementation is VERY stupid.  However, I trust it, whereas
     I don't trust computing kernels at present. */
   ans := [];
   for eps in Elements(G) do
      print "eps = ", eps;
      for k in [2..ell+1] do
//      for k in [10] do
         print "k = ", k;
         S := CuspForms(eps,k);
         for g in qExpansion(Newforms(S),prec) do
            print "g = ", qExpansion(Newforms(S), 4);
            if Type(BaseRing(Parent(g))) eq RngUPolRes then
               break;
            end if;
            for chi in Elements(G) do
               equal := true;
               for p in [q : q in [2..prec-1] | IsPrime(q) and N mod q ne 0 and q ne ell] do 
                  if Coefficient(f,p)*Evaluate(chi,p) ne Coefficient(g,p) then
                     equal := false;
                     break;
                  end if;
               end for;
               if equal then 
                  Append(~ans, <k, eps, chi>);
               end if;
            end for;
         end for;
      end for;
   end for;
   return ans;
end function;


function XXFindTwistInLowWeight(f, N)
   ell := Characteristic(BaseRing(Parent(f)));
   assert N mod ell ne 0;
   prec := AbsolutePrecision(f);
   pow := Order(IntegerRing(EulerPhi(N))!ell);  // ord divides ell^pow - 1 
   F<alp> := GF(ell^pow);
   G := DirichletGroup(N,CyclotomicField(EulerPhi(N)));
   Gbar := DirichletGroup(5,F);

// REALLY STUPID
   Z := [z : z in F | z ne 0 and Order(z) eq EulerPhi(N)];  

  /* This implementation is VERY stupid.  However, I trust it, whereas
     I don't trust computing kernels at present. */
   ans := [];
   for eps in Elements(G) do
      print "eps = ", eps;
      for k in [2..ell+1] do
         print "k = ", k;
         S0 := CuspForms(eps,k);
         for z in Z do
            S := BaseExtend(S0, F, z);
            print "S = ", S;
         for g in qExpansion(Newforms(S),prec) do
            print "g = ", qExpansion(Newforms(S), 4);
            if Type(BaseRing(Parent(g))) eq RngUPolRes then
               break;
            end if;
            for chi in Elements(Gbar) do
               equal := true;
               for p in [q : q in [2..prec-1] | IsPrime(q) and N mod q ne 0 and q ne ell] do 
                  if Coefficient(f,p)*Evaluate(chi,p) ne Coefficient(g,p) then
                     equal := false;
                     break;
                  end if;
               end for;
               if equal then 
                  Append(~ans, <k, eps, chi>);
               end if;
            end for;
         end for;
         end for;
      end for;
   end for;
   return ans;
end function;

