#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 1;
const long long INF = 0x3f3f3f3f;
const double Pi = acos(-1.0);
const long long MOD = 1e9 + 9;
const long long g5 = 383008016;
char a[maxn], b[maxn];
bool change;
int main() {
  int T;
  scanf("%d", &T);
  for (int Ti = 1; Ti <= T; ++Ti) {
    int n;
    scanf("%d %s %s", &n, a + 1, b + 1);
    queue<int> q;
    int posl = 1, posr = n, bpos = n;
    bool flag = 0;
    while (bpos >= 1) {
      if (flag == false) {
        if (a[posr] == b[bpos]) {
          --bpos;
          --posr;
          continue;
        }
        if (a[posl] == b[bpos]) {
          q.push(1);
          a[posl] = '0' + '1' - a[posl];
        } else {
          q.push(bpos);
          ++posl;
          --bpos;
          flag = true;
        }
      } else {
        if (a[posl] != b[bpos]) {
          ++posl;
          --bpos;
          continue;
        }
        if (a[posr] != b[bpos]) {
          q.push(1);
          a[posr] = '0' + '1' - a[posr];
        } else {
          q.push(bpos);
          --posr;
          --bpos;
          flag = false;
        }
      }
    }
    printf("%d", q.size());
    while (!q.empty()) {
      printf(" %d", q.front());
      q.pop();
    }
    printf("\n");
  }
  return 0;
}
