#include <bits/stdc++.h>
using namespace std;
void testcase() {
  int n;
  cin >> n;
  string a;
  cin >> a;
  string b;
  cin >> b;
  vector<int> switches;
  int idxHigh = n - 1;
  for (int i = 0; i < n; i++) {
    string a1 = a;
    if (idxHigh < 0 || a == b) {
      break;
    }
    if (a[0] != b[idxHigh]) {
      switches.push_back(idxHigh + 1);
      for (int j = 0; j <= idxHigh; j++) {
        if (a[idxHigh - j] == '1') {
          a1[j] = '0';
        } else {
          a1[j] = '1';
        }
      }
      idxHigh--;
    } else {
      switches.push_back(1);
      if (a[0] == '1') {
        a[0] = '0';
      } else {
        a[0] = '1';
      }
      switches.push_back(idxHigh + 1);
      for (int j = 0; j <= idxHigh; j++) {
        if (a[idxHigh - j] == '1') {
          a1[j] = '0';
        } else {
          a1[j] = '1';
        }
      }
      idxHigh--;
    }
    a = a1;
  }
  cout << switches.size() << ' ';
  for (int i = 0; i < switches.size(); i++) {
    cout << switches[i] << ' ';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x;
  cin >> x;
  for (long long i = 0; i < x; i++) {
    testcase();
    cout << '\n';
  }
  return 0;
}
