#include <bits/stdc++.h>
using namespace std;
char a[1005], b[1005];
int n;
vector<int> L;
inline void Reverse(int L) {
  int i, j;
  for (i = 1; i <= L; i++) {
    if (a[i] == '1')
      a[i] = '0';
    else
      a[i] = '1';
  }
  i = 1;
  j = L;
  while (i <= j) {
    swap(a[i], a[j]);
    i++;
    j--;
  }
}
int main() {
  int i, q;
  cin >> q;
  while (q--) {
    cin >> n >> (a + 1) >> (b + 1);
    for (i = n; i >= 1; i--)
      if (a[i] != b[i]) {
        if (a[1] == b[i]) {
          L.push_back(1);
          if (a[1] == '1')
            a[1] = '0';
          else
            a[1] = '1';
          L.push_back(i);
          Reverse(i);
        } else {
          L.push_back(i);
          Reverse(i);
        }
      }
    cout << L.size() << " ";
    for (auto it : L) cout << it << " ";
    cout << "\n";
    L.clear();
  }
  return 0;
}
