#include <bits/stdc++.h>
using namespace std;
char flip(char c) {
  if (c == '0')
    c = '1';
  else
    c = '0';
  char d = c;
  return d;
}
string reve(string s, int j) {
  string d = s;
  for (int i = 0; i < j; i++) {
    d[i] = flip(d[i]);
  }
  for (int i = 0; i < j / 2; i++) swap(d[i], d[j - i - 1]);
  return d;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a;
    cin >> b;
    int j = n - 1;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] != b[i]) {
        j = i;
        break;
      }
    }
    vector<int> ans;
    while (j >= 0) {
      char c = b[j];
      char d = a[0];
      if (b[j] == a[j])
        j--;
      else if (j == 0) {
        ans.push_back(1);
        j--;
      } else if (c == d) {
        ans.push_back(1);
        a[0] = flip(a[0]);
        ans.push_back(j + 1);
        a = reve(a, j + 1);
        j--;
      } else {
        ans.push_back(j + 1);
        a = reve(a, j + 1);
        j--;
      }
    }
    cout << ans.size() << " ";
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
