#include <bits/stdc++.h>
using namespace std;
int t, n, epos, spos, j, ans;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    string a, b;
    cin >> a;
    cin >> b;
    bool state = false;
    epos = n - 1;
    spos = 0;
    j = n - 1;
    vector<int> ans;
    while (j >= 0) {
      bool flag = false;
      if (state) {
        flag = (b[j] - '0') == !(a[epos] - '0');
      } else
        flag = b[j] == a[epos];
      if (!flag) {
        if (state) {
          if ((b[j] - '0') == !(a[spos] - '0')) ans.push_back(1);
          ans.push_back(abs(epos - spos) + 1);
        } else {
          if (b[j] == a[spos]) ans.push_back(1);
          ans.push_back(abs(epos - spos) + 1);
        }
        state = !state;
        if (spos < epos) {
          int tmp = epos;
          epos = spos + 1;
          spos = tmp;
        } else {
          int tmp = epos;
          epos = spos - 1;
          spos = tmp;
        }
      } else {
        if (spos > epos)
          epos++;
        else
          epos--;
      }
      j--;
    }
    cout << ans.size() << ' ';
    for (auto i : ans) cout << i << ' ';
    cout << endl;
  }
  return 0;
}
