#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    string s;
    cin >> s;
    for (long long(i) = (0); (i) < (n); (i)++) {
      a[i] = s[i] - '0';
    }
    cin >> s;
    for (long long(i) = (0); (i) < (n); (i)++) {
      b[i] = s[i] - '0';
    }
    vector<int> ans;
    int flag = 1;
    int l = 0;
    int r = n - 1;
    int ptr = n - 1;
    while (l <= r) {
      if (flag) {
        if (a[r] == b[ptr]) {
          ptr--;
          r--;
          continue;
        } else {
          if (a[l] == b[ptr]) {
            ans.push_back(1);
          }
          ans.push_back(ptr + 1);
          l++;
          flag = 0;
        }
      } else {
        if (a[l] ^ 1 == b[ptr]) {
          ptr--;
          l++;
          continue;
        } else {
          if (a[r] ^ 1 == b[ptr]) {
            ans.push_back(1);
          }
          ans.push_back(ptr + 1);
          r--;
          flag = 1;
        }
      }
      ptr--;
    }
    cout << ans.size() << " ";
    for (long long(i) = (0); (i) < (ans.size()); (i)++) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
}
