#include <bits/stdc++.h>
using namespace std;
string op(string str, int i) {
  int en = i, be = 0;
  while (be <= en) {
    if (str[be] == str[en]) {
      if (str[be] == '1')
        str[be] = str[en] = '0';
      else
        str[be] = str[en] = '1';
    }
    be++;
    en--;
  }
  return str;
}
void fun() {
  int n;
  cin >> n;
  bool arr[n];
  string src, target;
  cin >> src >> target;
  int count = 0;
  std::vector<int> v;
  for (int i = n - 1; i >= 0; i--) {
    if (src[i] == target[i]) continue;
    if (src[i] == src[0]) {
      src = op(src, i);
      count++;
      v.push_back(i + 1);
    } else {
      if (src[0] == '0')
        src[0] = '1';
      else
        src[0] = '0';
      count++;
      v.push_back(1);
      if (i > 0) {
        src = op(src, i);
        count++;
        v.push_back(i + 1);
      }
    }
  }
  cout << count << " ";
  for (int i : v) cout << i << " ";
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    fun();
  }
}
