description: Let's call a sequence of integers x_1, x_2, ..., x_k MEX-correct if for all i (1 ≤ i ≤ k) |x_i - \operatorname{MEX}(x_1, x_2, ..., x_i)| ≤ 1 holds. Where \operatorname{MEX}(x_1, ..., x_k) is the minimum non-negative integer that doesn't belong to the set x_1, ..., x_k. For example, \operatorname{MEX}(1, 0, 1, 3) = 2 and \operatorname{MEX}(2, 1, 5) = 0.
  
  You are given an array a consisting of n non-negative integers. Calculate the number of non-empty MEX-correct subsequences of a given array. The number of subsequences can be very large, so print it modulo 998244353. 
  
  Note: a subsequence of an array a is a sequence [a_{i_1}, a_{i_2}, ..., a_{i_m}] meeting the constraints 1 ≤ i_1 < i_2 < ... < i_m ≤ n. If two different ways to choose the sequence of indices [i_1, i_2, ..., i_m] yield the same subsequence, the resulting subsequence should be counted twice (i. e. two subsequences are different if their sequences of indices [i_1, i_2, ..., i_m] are not the same).
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
  
  The first line of each test case contains a single integer n (1 ≤ n ≤ 5 ⋅ 10^5).
  
  The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ n).
  
  The sum of n over all test cases doesn't exceed 5 ⋅ 10^5.
  
  Output
  
  For each test case, print a single integer — the number of non-empty MEX-correct subsequences of a given array, taken modulo 998244353.
  
  Example
  
  Input
  
  
  4
  3
  0 2 1
  2
  1 0
  5
  0 0 0 0 0
  4
  0 1 2 3
  
  
  Output
  
  
  4
  2
  31
  7
  
  Note
  
  In the first example, the valid subsequences are [0], [1], [0,1] and [0,2].
  
  In the second example, the valid subsequences are [0] and [1].
  
  In the third example, any non-empty subsequence is valid. 
solution: public class D {
  
  	public Object solve () {
  		int N = sc.nextInt();
  		int [] A = sc.nextInts();
  
  		long [] F = new long [N+2], G = new long [N+2]; F[0] = 1;
  		long res = 0;
  
  		for (int a : A) {
  			long r = F[a+1] + G[a+1] + F[a];
  			if (a > 0)
  				r += F[a-1] + G[a-1];
  
  			res = mod(res + r);
  
  			if (a > 0)
  				G[a-1] = mod(G[a-1] + F[a-1] + G[a-1]);
  			F[a+1] = mod(F[a+1] + F[a] + F[a+1]);
  			G[a+1] = mod(G[a+1] + G[a+1]);
  		}
  
  		return res;
  	}
  
  	private static final int CONTEST_TYPE = 2;
  
  	private static void init () {
  	}
  
  	private static final int MOD = 998244353;
  	private static long mod (long x) { return mod(x, MOD); }
  	private static long mod (long x, long mod) { return ((x % mod) + mod) % mod; }
  	//////////////////////////////////////////////////////////////////////////////////// OFF
  	private static IOUtils.MyScanner sc = new IOUtils.MyScanner();
  	private static class IOUtils {
  		public static class MyScanner {
  			public String next () { newLine(); return line[index++]; }
  			public int nextInt () { return Integer.parseInt(next()); }
  			public String nextLine () { line = null; return readLine(); }
  			public String [] nextStrings () { return split(nextLine()); }
  			public int [] nextInts () {
  				String [] S = nextStrings(); int N = S.length;
  				int [] res = new int [N];
  				for (int i = 0; i < N; ++i)
  					res[i] = Integer.parseInt(S[i]);
  				return res;
  			}
  			//////////////////////////////////////////////
  			private boolean eol () { return index == line.length; }
  			private String readLine () {
  				try {
  					int b;
  					StringBuilder res = new StringBuilder();
  					while ((b = System.in.read()) < ' ')
  						continue;
  					res.append((char)b);
  					while ((b = System.in.read()) >= ' ')
  						res.append((char)b);
  					return res.toString();
  				} catch (Exception e) {
  					throw new Error (e);
  				}
  			}
  			private MyScanner () {
  				try {
  					while (System.in.available() == 0)
  						Thread.sleep(1);
  					start();
  				} catch (Exception e) {
  					throw new Error(e);
  				}
  			}
  			private String [] line;
  			private int index;
  			private void newLine () {
  				if (line == null || eol()) {
  					line = split(readLine());
  					index = 0;
  				}
  			}
  			private String [] split (String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
  		}
  		private static String build (Object o, Object ... A) { return buildDelim(" ", o, A); }
  		private static String buildDelim (String delim, Object o, Object ... A) {
  			java.util.List<String> str = new java.util.ArrayList<>();
  			append(str, o);
  			for (Object p : A)
  				append(str, p);
  			return String.join(delim, str.toArray(new String [0]));
  		}
  		//////////////////////////////////////////////////////////////////////////////////
  		private static java.text.DecimalFormat formatter = new java.text.DecimalFormat("#.#########");
  		private static void start () { if (t == 0) t = millis(); }
  		private static void append (java.util.function.Consumer<Object> f, java.util.function.Consumer<Object> g, Object o) {
  			if (o.getClass().isArray()) {
  				int len = java.lang.reflect.Array.getLength(o);
  				for (int i = 0; i < len; ++i)
  					f.accept(java.lang.reflect.Array.get(o, i));
  			}
  			else if (o instanceof Iterable<?>)
  				((Iterable<?>)o).forEach(f::accept);
  			else
  				g.accept(o instanceof Double ? formatter.format(o) : o);
  		}
  		private static void append (java.util.List<String> str, Object o) {
  			append(x -> append(str, x), x -> str.add(x.toString()), o);
  		}
  		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
  		private static void flush () { pw.flush(); System.out.flush(); }
  		private static void print (Object o, Object ... A) {
  			String res = build(o, A);
  			if (DEBUG == 2)
  				err(res, '(', time(), ')');
  			if (res.length() > 0)
  				pw.println(res);
  			if (DEBUG == 1)
  				flush();
  		}
  		private static void err (Object o, Object ... A) { System.err.println(build(o, A)); }
  		private static int DEBUG;
  		private static void exit () {
  			String end = "------------------" + System.lineSeparator() + time();
  			switch(DEBUG) {
  			case 1: print(end); break;
  			case 2: err(end); break;
  			}
  			IOUtils.pw.close();
  			System.out.flush();
  			System.exit(0);
  		}
  		private static long t;
  		private static long millis () { return System.currentTimeMillis(); }
  		private static String time () { return "Time: " + (millis() - t) / 1000.0; }
  		private static void run (int N) {
  			try { DEBUG = Integer.parseInt(System.getProperties().get("DEBUG").toString()); }
  			catch (Throwable t) {}
  
  			for (int n = 1; n <= N; ++n) {
  				Object res = new D().solve();
  				if (res != null) {
  					@SuppressWarnings("all")
  					Object o = CONTEST_TYPE == 0 ? "Case #" + n + ": " + build(res) : res;
  					print(o);
  				}
  			}
  			exit();
  		}
  	}
  	////////////////////////////////////////////////////////////////////////////////////
  	public static void main (String[] args) {
  		@SuppressWarnings("all")
  		int N = CONTEST_TYPE == 1 ? 1 : sc.nextInt();
  		init();
  		IOUtils.run(N);
  	}
  }
  