#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  bool inv = false, rev = false;
  long long int i = 0, j = n - 1;
  vector<long long int> ans;
  for (long long int k = n - 1; k >= 0; k--) {
    if (rev) {
      if (s[j] != t[k]) ans.push_back(1);
      ans.push_back(k + 1);
      j--;
    } else {
      if (s[i] == t[k]) ans.push_back(1);
      ans.push_back(k + 1);
      i++;
    }
    rev = !rev;
  }
  cout << ans.size() << " ";
  for (long long int x : ans) cout << x << " ";
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  for (long long int i = 0; i < (long long int)(t); i++) {
    solve();
  }
}
