#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = INT_MAX - 1;
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    bool arr1[n];
    bool arr2[n];
    for (int i = 0; i < n; i++) {
      char c;
      cin >> c;
      if (c == '1') {
        arr1[i] = true;
      } else {
        arr1[i] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      char c;
      cin >> c;
      if (c == '1') {
        arr2[i] = true;
      } else {
        arr2[i] = false;
      }
    }
    vector<int> ans;
    int cur = 0;
    int compare = n - 1;
    for (int i = 0; i < n; i++) {
      bool item = 0;
      if (i % 2 == 0) {
        item = arr1[cur];
      } else {
        item = arr1[n - cur - 1];
      }
      if (i % 2 == 0) {
        if (item == arr2[compare]) {
          ans.push_back(1);
        }
        ans.push_back(compare + 1);
      } else {
        if (item != arr2[compare]) {
          ans.push_back(1);
        }
        ans.push_back(compare + 1);
      }
      compare--;
      if (i % 2 == 1) {
        cur++;
      }
    }
    cout << ans.size() << " ";
    for (int i : ans) {
      cout << i << " ";
    }
    cout << "\n";
  }
}
