#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const double inf = 1e15;
char flip(char x) {
  if (x == '0')
    return '1';
  else
    return '0';
}
void solve() {
  long long int n;
  cin >> n;
  ;
  string a, b;
  cin >> a >> b;
  long long int count = 0;
  vector<long long int> ans;
  long long int f = 0;
  long long int j = 0;
  for (long long int i = n - 1; i >= 0; i--) {
    if (f == 0) {
      int x = (a[j] + count - '0') % 2;
      char xx = '0' + x;
      if (b[i] == xx) {
        ans.push_back(1);
        a[j] = flip(xx);
      }
      ans.push_back(i + 1);
      f ^= 1;
      count++;
    } else {
      int x = (a[n - 1 - j] + count - '0') % 2;
      char xx = '0' + x;
      if (b[i] == xx) {
        ans.push_back(1);
        a[n - 1 - j] = flip(xx);
      }
      ans.push_back(i + 1);
      f ^= 1;
      j++;
      count++;
    }
  }
  cout << ans.size() << " ";
  for (auto i : ans) cout << i << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  for (long long int i = 1; i <= t; i++) {
    solve();
  }
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
  return 0;
}
