#include <bits/stdc++.h>
using namespace std;
long long cl(long long n, long long m) {
  if (n % m)
    return n / m + 1;
  else
    return n / m;
}
long long pw(long long a, long long b, long long M) {
  a %= M;
  long long r = 1;
  while (b > 0) {
    if (b & 1) r = r * a % M;
    a = a * a % M;
    b >>= 1;
  }
  return r;
}
const long long N = 1e6 + 5;
char mul(char t, long long x) {
  long long b = t - '0';
  b = b ^ x;
  char c = b + '0';
  return c;
}
signed main() {
  long long TT;
  cin >> TT;
  while (TT--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    long long x = 0;
    long long l = 0, r = a.size() - 1;
    long long t = b.size() - 1;
    vector<long long> ans;
    for (long long i = t; i >= 0; i--) {
      if (l <= r) {
        if (mul(a[r], x) == b[i]) {
          r--;
          continue;
        } else {
          if (a[l] == a[r]) {
            ans.push_back(i + 1);
            x = x ^ 1;
            l++;
            swap(l, r);
          } else {
            ans.push_back(1);
            a[l] = mul(a[l], 1);
            ans.push_back(i + 1);
            x = x ^ 1;
            l++;
            swap(l, r);
          }
        }
      } else {
        if (mul(a[r], x) == b[i]) {
          r++;
          continue;
        } else {
          if (a[l] == a[r]) {
            ans.push_back(i + 1);
            x = x ^ 1;
            l--;
            swap(l, r);
          } else {
            ans.push_back(1);
            a[l] = mul(a[l], 1);
            ans.push_back(i + 1);
            x = x ^ 1;
            l--;
            swap(l, r);
          }
        }
      }
    }
    cout << ans.size() << " ";
    for (auto it : ans) {
      cout << it << " ";
    }
    cout << endl;
  }
}
