#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int t, n, a[N], b[N], rev;
queue<int> order;
char x;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> t;
  a[0] = 1;
  while (t--) {
    rev = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> x;
      a[i] = x - '0';
    }
    for (int i = 1; i <= n; i++) {
      cin >> x;
      b[i] = x - '0';
    }
    int right = n, left = 1;
    while (true) {
      ;
      if (rev)
        while (a[left] != b[n] && n > 0) {
          left++;
          n--;
        }
      else
        while (a[right] == b[n] && n > 0) {
          right--;
          n--;
        }
      if (n < 1) break;
      if (rev && a[right] != b[n] || n == 1)
        order.push(1);
      else if (rev == 0 && a[left] == b[n] || n == 1)
        order.push(1);
      if (n != 1) order.push(n);
      if (rev)
        right--;
      else
        left++;
      rev ^= 1;
      n--;
    }
    cout << order.size() << " ";
    while (!order.empty()) {
      cout << order.front() << " ";
      order.pop();
    }
    cout << "\n";
  }
}
