#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 99;
const long long INFLL = 2e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    string a, b;
    cin >> n >> a >> b;
    vector<int> ans;
    int l = 0, r = n - 1, x = 0;
    for (int i = n - 1; i >= 0; --i) {
      int id1 = l, id2 = r;
      if (x & 1) swap(id1, id2);
      char c = a[id2];
      if (x & 1) c = (a[id2] == '0') ? '1' : '0';
      if (c != b[i]) {
        if (x & 1) a[id1] = (a[id1] == '0') ? '1' : '0';
        if (b[i] == a[id1]) ans.push_back(1);
        ans.push_back(i + 1);
        if (x & 1)
          --r;
        else
          ++l;
        x ^= 1;
      } else {
        if (x & 1)
          ++l;
        else
          --r;
      }
    }
    cout << ans.size();
    for (int x : ans) cout << " " << x;
    puts("");
  }
  return 0;
}
