#include <bits/stdc++.h>
using namespace std;
void invert(string& a, int p) {
  for (int i = 0; i < p; ++i) {
    a[i] = (a[i] == '0' ? '1' : '0');
  }
  int l = 0;
  int r = p - 1;
  while (l < r) {
    char x = a[l];
    char y = a[r];
    a[l] = y;
    a[r] = x;
    l++;
    r--;
  }
}
int main(int argc, char* argv[]) {
  int t;
  cin >> t;
  while (t-- > 0) {
    int n;
    cin >> n;
    string a;
    cin >> a;
    string b;
    cin >> b;
    vector<int> v;
    for (int i = n - 1; i >= 0; --i) {
      if (a[i] != b[i]) {
        if (a[0] == b[i]) {
          v.push_back(1);
          invert(a, 1);
        }
        v.push_back(i + 1);
        invert(a, i + 1);
      }
    }
    cout << v.size();
    for (auto q : v) cout << " " << q;
    cout << endl;
  }
  return 0;
}
