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: import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.PrintStream;
  import java.util.InputMismatchException;
  import java.util.StringTokenizer;
  
  /*
  1
  6
  2 1 3 1 1 1
  */
  public class A4 {
      
      void solve() {
          int n = cint();
          int[] a = carr_int(n);
  //
  //        TIntList chain = new TIntList();
  //        dfs(a, 0, chain, false);
  
  
          long[] up = new long[n+3]; // только возрастающие подпоследовательности
          long[] w = new long[n+3]; // с одним пропуском
          
          long up_x = 0, up_x_1 = 0, up_x_2 = 0, w_x = 0, w_xp2 = 0;
          
          long result = 0;
          for (int i = 0; i < n; i++) {
              int x = a[i];
              up_x = up[x];
              up_x_1 = x >= 1 ? up[x-1] : 0; 
              up_x_2 = x >= 2 ? up[x-2] : 0; 
              w_x = w[x];
              w_xp2 = w[x+2];
  
              up[x] = (up[x] + up_x) % MOD;
              result += up_x;
              if (x > 0) {
                  up[x] = (up[x] + up_x_1) % MOD;
                  result += up_x_1;
              }
  
              w[x] = (w[x] + w_x) % MOD;
              result += w_x;
              if (x >= 2) {
                  w[x] = (w[x] + up_x_2) % MOD;
                  result += up_x_2;
              }
  
              w[x+2] = (w[x+2] + w_xp2) % MOD;
              result += w_xp2;
              
              if (x == 0) {
                  up[0] = (up[0] + 1) % MOD;
                  result++;
              }
              if (x == 1) { 
                  w[1] = (w[1] + 1) % MOD;
                  result++;
              }
              
              result = result % MOD;
          }
  
          cout(result);
      }
  
  //
  //    void dfs(int[] a, int index, TIntList chain, boolean printed) {
  //        if (chain.len > 0 && !printed) {
  //            boolean ok = true;
  //            for (int i = 0; i < chain.len; i++) {
  //                int mex = mex(chain, i+1);
  //                ok &= (Math.abs(chain.x[i] - mex) <= 1);
  //            }
  //            if (ok) {
  //                System.out.println(Arrays.toString(chain.toArray()));
  //            }
  //        }
  //
  //        if (index >= a.length) {
  //            return;
  //        }
  //
  //        dfs(a, index + 1, chain, true);
  //        chain.add(a[index]);
  //        dfs(a, index + 1, chain, false);
  //        chain.removeLast();
  //    }
  //
  //    int mex(TIntList a, int len) {
  //        Set<Integer> set = new HashSet<>();
  //        for (int i = 0; i < len; i++) {
  //            set.add(a.x[i]);
  //        }
  //        for (int i = 0; i < 100000000; i++) {
  //            if (!set.contains(i)) {
  //                return i;
  //            }
  //        }
  //        return -1;
  //    }
  
  
      long MOD = 998244353;
  
      long minus1(long a) {
          return a == 0 ? MOD - 1 : a - 1;
      }
  
      long pow2(int n) {
          if (n == 0) {
              return 1;
          }
          if (n == 1) {
              return 2;
          }
          return (pow2(n / 2) * pow2(n - n / 2)) % MOD;
      }
  
  
      public static void main(String... args) throws Exception {
          //gen(500_000);
          int t = in.nextInt();
          for (int test = 0; test < t; test++) {
              new A4().solve();
          }
      }
  
      static void gen(int n) throws Exception {
          PrintStream ps = new PrintStream("file.in");
          ps.println(1);
          ps.println(n);
          for (int i = 0; i < n; i++) {
              if (i != 0) {
                  ps.print(' ');
              }
              ps.print(500_000);
          }
          ps.close();
      }
  
      static final QuickReader in = new QuickReader(System.in);
  //    static QuickReader in;
  //
  //    static {
  //        try {
  //            in = new QuickReader(new FileInputStream("file.in"));
  //        } catch (FileNotFoundException e) {
  //            //in = null;
  //            throw new RuntimeException();
  //        }
  //    }
  
      static final PrintStream out = System.out;
  
      static int cint() {
          return in.nextInt();
      }
  
      static long clong() {
          return in.nextLong();
      }
  
      static String cstr() {
          return in.nextLine();
      }
  
      static int[] carr_int(int n) {
          return in.nextInts(n);
      }
  
      static long[] carr_long(int n) {
          return in.nextLongs(n);
      }
  
      static void cout(int... a) {
          StringBuilder buf = new StringBuilder();
          for (int i = 0; i < a.length; i++) {
              if (i != 0) {
                  buf.append(' ');
              }
              buf.append(a[i]);
          }
          out.println(buf);
      }
  
      static void cout(long... a) {
          StringBuilder buf = new StringBuilder();
          for (int i = 0; i < a.length; i++) {
              if (i != 0) {
                  buf.append(' ');
              }
              buf.append(a[i]);
          }
          out.println(buf);
      }
  
      static void cout(Object o) {
          out.println(o);
      }
  
      static class QuickReader {
          BufferedReader in;
          StringTokenizer token;
  
          public QuickReader(InputStream ins) {
              in = new BufferedReader(new InputStreamReader(ins));
              token = new StringTokenizer("");
          }
  
          public boolean hasNext() {
              while (!token.hasMoreTokens()) {
                  try {
                      String s = in.readLine();
                      if (s == null) {
                          return false;
                      }
                      token = new StringTokenizer(s);
                  } catch (IOException e) {
                      throw new InputMismatchException();
                  }
              }
              return true;
          }
  
          public String next() {
              hasNext();
              return token.nextToken();
          }
  
          public String nextLine() {
              try {
                  String s = in.readLine();
                  token = new StringTokenizer("");
                  return s;
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
          }
  
          public int nextInt() {
              return Integer.parseInt(next());
          }
  
          public int[] nextInts(int n) {
              int[] res = new int[n];
              for (int i = 0; i < n; i++) {
                  res[i] = nextInt();
              }
              return res;
          }
  
          public long nextLong() {
              return Long.parseLong(next());
          }
  
          public long[] nextLongs(int n) {
              long[] res = new long[n];
              for (int i = 0; i < n; i++) {
                  res[i] = nextLong();
              }
              return res;
          }
      }
  }
  