#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    long long c = 0, inv = 0;
    vector<long long> v;
    map<char, char> m;
    m['1'] = '0';
    m['0'] = '1';
    long long l = 0, r = n - 1;
    for (long long i = n - 1; i > 0; i--) {
      if (inv == 0) {
        bool flag = false;
        if (a[r] != b[i]) {
          flag = true;
          if (a[l] == b[i]) {
            c++;
            v.push_back(1);
            a[l] = m[a[l]];
          }
          c++;
          v.push_back(i + 1);
          inv = 1 - inv;
          swap(l, r);
          r++;
        }
        if (!flag) r--;
      } else {
        bool flag = false;
        if (a[r] == b[i]) {
          flag = true;
          if (a[l] != b[i]) {
            c++;
            v.push_back(1);
            a[l] = m[a[l]];
          }
          c++;
          v.push_back(i + 1);
          inv = 1 - inv;
          swap(l, r);
          r--;
        }
        if (!flag) r++;
      }
    }
    if (inv == 0) {
      if (a[r] != b[0]) {
        c++;
        v.push_back(1);
      }
    } else {
      if (a[r] == b[0]) {
        c++;
        v.push_back(1);
      }
    }
    cout << c << " ";
    for (auto i : v) cout << i << " ";
    cout << "\n";
    ;
  }
  return 0;
}
