#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int nax = 1e5 + 200;
int t, n;
string s;
int a[nax], b[nax];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(20) << fixed;
  cin >> t;
  while (t--) {
    cin >> n >> s;
    for (int i = 0; i < (int)n; ++i) {
      a[i] = s[i] - '0';
    }
    cin >> s;
    for (int i = 0; i < (int)n; ++i) {
      b[i] = s[i] - '0';
    }
    int j = n - 1;
    vector<int> ops;
    ops.reserve(3 * n);
    int i = 0;
    int f = 0;
    int len = 0;
    int l = 0, r = n - 1;
    while (j >= 0) {
      if ((a[i] ^ f) == b[j]) ops.push_back(1);
      ops.push_back(n - len);
      if (f) {
        --r;
        i = l;
      } else {
        ++l;
        i = r;
      }
      --j;
      f ^= 1;
      ++len;
    }
    cout << ((int)ops.size()) << " ";
    for (int i : ops) {
      cout << i << " ";
    }
    cout << '\n';
  }
}
