program SALADS;

{$APPTYPE CONSOLE}

uses
  SysUtils,math;

var
 f:text;
 i,j,k,n,S:integer;
 M:ARRAY[1..10000000] OF STRING ;
begin
 assign(f,'SALADS.IN');
 reset(f);
 readln(f,k);
 for i:=1 to k do begin
  readln(f,n);
  S:=0;
  {for j:= 1 to n do begin

  end;}
  s:=round(power(n-1,n-2))+2;
  writeln(s);
 end;
 close(f);
end.
