#include <bits/stdc++.h>
using namespace std;
int64_t ans, n, k, m, r[100005];
char s[100005], t[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int64_t tt;
  cin >> tt;
  while (tt--) {
    cin >> n;
    cin >> s;
    cin >> t;
    vector<int> ans;
    m = n - 1;
    int i = 0, j = n - 1;
    while (i < j) {
      r[m--] = i;
      i++;
      r[m--] = j;
      j--;
    }
    if (i == j) r[m] = i;
    m = 0;
    for (int i = n - 1; i >= 0; i--) {
      if ((s[r[i]] - '0' + m) % 2 == t[i] - '0') ans.push_back(1);
      ans.push_back(i + 1);
      m++;
    }
    cout << (int)ans.size() << " ";
    for (auto i : ans) cout << i << " ";
    cout << "\n";
  }
  return 0;
}
