#include <bits/stdc++.h>
const int MAX = 1e5 + 10;
const int MOD = 1e9 + 10;
const int INF = 0x3f3f3f3f;
using namespace std;
int n;
string s1, s2;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    vector<int> cnt;
    cin >> n >> s1 >> s2;
    char fg = s1[0];
    for (int i = 0; i < n - 1; i++)
      if (s1[i] != s1[i + 1]) {
        cnt.push_back(i + 1);
        fg = s1[i + 1];
      }
    for (int i = n - 1; i >= 0; i--) {
      if (s2[i] != fg) {
        cnt.push_back(i + 1);
        fg = (fg == '0' ? '1' : '0');
      }
    }
    cout << cnt.size() << " ";
    for (int i = 0; i < cnt.size(); i++) cout << cnt[i] << " ";
    cout << endl;
  }
  return 0;
}
