#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    string s2;
    cin >> s;
    cin >> s2;
    vector<long long> arr(n);
    vector<long long> arr2(n);
    for (long long i = 0; i < n; i++) {
      arr[i] = (long long)s[i] - (long long)'0';
      arr2[i] = (long long)s2[i] - (long long)'0';
    }
    long long left = 0;
    long long right = n - 1;
    long long add = 0;
    long long count = 0;
    vector<long long> ans;
    while (left < right) {
      if (add % 2 == 0) {
        if ((arr[right] + add) % 2 == arr2[n - count - 1]) {
          right--;
          count++;
          continue;
        }
        if ((arr[left] + add) % 2 == arr2[n - count - 1]) {
          ans.push_back(1);
          arr[left] = (arr[left] + 1) % 2;
        }
        ans.push_back(n - count);
        for (long long i = left; i < right; i++) {
          if (arr[right - (i - left)] != arr[i]) {
            right--;
            count++;
          } else {
            break;
          }
        }
        add++;
      } else {
        if ((arr[left] + add) % 2 == arr2[n - count - 1]) {
          left++;
          count++;
          continue;
        }
        if ((arr[right] + add) % 2 == arr2[n - count - 1]) {
          ans.push_back(1);
          arr[right] = (arr[right] + 1) % 2;
        }
        ans.push_back(n - count);
        for (long long i = right; i > left; i--) {
          if (arr[left + (right - i)] != arr[i]) {
            left++;
            count++;
          } else {
            break;
          }
        }
        add++;
      }
    }
    if ((arr[left] + add) % 2 != arr2[0]) ans.push_back(1);
    cout << ans.size() << " ";
    for (long long nxt : ans) {
      cout << nxt << " ";
    }
    cout << "\n";
  }
  return 0;
}
