#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k, n, m, t, x, y, a, b, c;
  cin >> t;
  while (t--) {
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    vector<long long int> vec;
    i = n - 1;
    while (i > 1) {
      if (s1[i] == s2[i]) {
      } else {
        if (s1[0] != s2[i]) {
          for (j = 0; j <= i; j++) {
            if (s1[j] == '0')
              s1[j] = '1';
            else
              s1[j] = '0';
          }
          reverse(s1.begin(), s1.begin() + j);
          vec.push_back(i + 1);
        } else {
          vec.push_back(1);
          if (s1[0] == '0')
            s1[0] = '1';
          else
            s1[0] = '0';
          vec.push_back(i + 1);
          for (j = 0; j <= i; j++) {
            if (s1[j] == '0')
              s1[j] = '1';
            else
              s1[j] = '0';
          }
          reverse(s1.begin(), s1.begin() + j);
        }
      }
      i--;
    }
    if (s1[1] != s2[1]) {
      if (s1[0] == s2[1]) {
        vec.push_back(1);
        vec.push_back(2);
        if (s1[0] == '1')
          s1[0] = '0';
        else
          s1[0] = '1';
        if (s1[0] == '0')
          s1[0] = '1';
        else
          s1[0] = '0';
        if (s1[1] == '0')
          s1[1] = '1';
        else
          s1[1] = '0';
        swap(s1[0], s1[1]);
      } else {
        vec.push_back(2);
        if (s1[0] == '0')
          s1[0] = '1';
        else
          s1[0] = '0';
        if (s1[1] == '0')
          s1[1] = '1';
        else
          s1[1] = '0';
        swap(s1[0], s1[1]);
      }
    }
    if (s1[0] != s2[0]) vec.push_back(1);
    cout << vec.size() << " ";
    for (i = 0; i < vec.size(); i++) cout << vec[i] << " ";
    cout << endl;
  }
}
