#include <bits/stdc++.h>
using namespace std;
const long long int N = 1000000000;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t-- > 0) {
    int n;
    cin >> n;
    string s, s1;
    cin >> s >> s1;
    int x = 0;
    int op = 0;
    vector<int> opr;
    for (int i = n - 1; i >= 0; i--) {
      if (op % 2 == 0) {
        if (s[x + i] == s1[i]) continue;
        if (s[x] != s[x + i]) opr.push_back(1);
        opr.push_back(i + 1);
        op++;
        x = x + i;
      } else {
        char c = s[x - i] == '0' ? '1' : '0';
        char c1 = s[x] == '0' ? '1' : '0';
        if (c == s1[i]) continue;
        if (c != c1) opr.push_back(1);
        opr.push_back(i + 1);
        op++;
        x = x - i;
      }
    }
    cout << opr.size() << " ";
    for (auto i : opr) cout << i << " ";
    cout << endl;
  }
}
