#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n;
    string a, b;
    cin >> a >> b;
    int sm = 0;
    vector<int> v;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] != b[i]) {
        if (a[i] != a[0]) {
          sm++;
          a[0] = (a[0] == '0' ? '1' : '0');
          v.push_back(1);
        }
        sm++;
        v.push_back(i + 1);
        for (int j = 0; j <= i; j++) a[j] = a[j] == '0' ? '1' : '0';
        reverse(a.begin(), a.end() - (n - i) + 1);
      }
    }
    cout << sm << " ";
    for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << endl;
  }
}
