#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    string a, b;
    cin >> n >> a >> b;
    int f = 0;
    vector<int> v;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] != b[i]) {
        f++;
        if (a[0] == b[i]) {
          v.push_back(1);
          if (a[0] == '1')
            a[0] = '0';
          else
            a[0] = '1';
        }
        v.push_back(i + 1);
        string s1 = "";
        for (int j = i; j >= 0; j--) {
          char ch;
          if (a[j] == '1')
            ch = '0';
          else
            ch = '1';
          s1 += ch;
        }
        a = s1 + a.substr(i + 1, n - i - 1);
      }
    }
    cout << v.size() << " ";
    for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << "\n";
  }
  return 0;
}
