#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& t) {
  t = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  t *= f;
}
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const long long Inf = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x7f7f7f7f;
const double eps = 1e-5;
const double Pi = acos(-1);
string s1, s2;
vector<int> res;
int main(void) {
  int T;
  read(T);
  while (T--) {
    res.clear();
    int n;
    read(n);
    cin >> s1 >> s2;
    int cnt = 0;
    for (int i = 0; i <= n - 1; i++) {
      int pos = n - 1 - i / 2;
      if (i % 2 == 0) pos = n - 1 - pos;
      char ch = s1[pos];
      if (cnt & 1) ch = (ch == '0' ? '1' : '0');
      if (ch == s2[n - i - 1]) res.push_back(1);
      res.push_back(n - i);
      cnt++;
    }
    printf("%d ", res.size());
    for (int i = 0; i < res.size(); i++) printf("%d ", res[i]);
    printf("\n");
  }
  return 0;
}
