#include <bits/stdc++.h>
using namespace std;
void func(string &s1, int index, int length) {
  for (int i = 0; i <= index; i++) {
    if (s1[i] == '0')
      s1[i] = '1';
    else
      s1[i] = '0';
  }
  string s2 = s1;
  for (int i = 0; i <= index; i++) {
    s2[i] = s1[index - i];
  }
  for (int i = 0; i <= index; i++) s1[i] = s2[i];
}
int main() {
  int t;
  cin >> t;
  for (int cas = 0; cas < t; cas++) {
    int length;
    cin >> length;
    string s1, s2;
    cin >> s1 >> s2;
    int count = 0;
    vector<int> prefix;
    for (int i = length - 1; i >= 0; i--) {
      if (s1[i] != s2[i]) {
        if (s1[0] == s2[i]) {
          count++;
          prefix.push_back(1);
          if (s1[0] == '0')
            s1[0] = '1';
          else
            s1[0] = '0';
          count++;
          prefix.push_back(i + 1);
          func(s1, i, length);
        } else {
          func(s1, i, length);
          count++;
          prefix.push_back(i + 1);
        }
      }
    }
    cout << count << " ";
    for (int i = 0; i < prefix.size(); i++) {
      cout << prefix[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
