#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void flip(string& a, int n) {
  for (int i = 0; i < n; i++) {
    if (a[i] == '0') {
      a[i] = '1';
    } else {
      a[i] = '0';
    }
  }
  reverse(a.begin(), a.begin() + n);
}
void solve() {
  int n;
  cin >> n;
  string a, b;
  cin >> a;
  cin >> b;
  vector<int> ans;
  int i = 0;
  int j = n - 1;
  int f = 0;
  int l = n - 1;
  while (j >= 0 && a[j] == b[j]) {
    j--;
    l--;
  }
  int flag = 0;
  while (j >= 0) {
    if (flag && a[f] == b[j]) {
      ans.push_back(j + 1);
      while (j >= 0 && a[f] == b[j]) {
        j--;
        f--;
        flag = 0;
      }
      int x = f;
      f = l;
      l = x;
    } else if (!flag && a[f] != b[j]) {
      ans.push_back(j + 1);
      while (j >= 0 && a[f] != b[j]) {
        j--;
        f++;
        flag = 1;
      }
      int x = f;
      f = l;
      l = x;
    } else {
      ans.push_back(1);
      if (a[f] == '0') {
        a[f] = '1';
      } else {
        a[f] = '0';
      }
    }
  }
  cout << ans.size() << " ";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
