#include <bits/stdc++.h>
using namespace std;
int arr[100005][2];
char str[100005];
vector<int> vec;
int main() {
  int i, j, k, a, b, c, n, m, t, T, cnt;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    vec.clear();
    for (i = 0; i < 2; i++) {
      scanf("%s", str);
      for (j = 0; j < n; j++) arr[j + 1][i] = str[j] - '0';
    }
    m = 0;
    cnt = 0;
    for (i = n; i >= 2; i--) {
      if (cnt % 2 == 0)
        j = i - m;
      else
        j = -i + m;
      if ((arr[j][0] + cnt) % 2 == arr[i][1]) continue;
      if (arr[i][1] == arr[1][0]) {
        vec.push_back(1);
        arr[1][0] = 1 - arr[1][0];
      }
      vec.push_back(i);
      m = 1 + i - m;
      arr[1][0] = 1 - (arr[j][0] + cnt) % 2;
      cnt++;
    }
    if (arr[1][0] != arr[1][1]) vec.push_back(1);
    printf("%d ", vec.size());
    for (i = 0; i < vec.size(); i++) printf("%d ", vec[i]);
    printf("\n");
  }
}
