#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, x, j, t, y, k;
  cin >> t;
  while (t--) {
    long long m;
    cin >> n;
    string p, q;
    cin >> p >> q;
    long long r = 0;
    long long first = 0, end = n - 1;
    long long x = n;
    vector<long long> v;
    for (i = n - 1; i > 0; i--) {
      if (p[i] != q[i]) {
        if (p[0] == '0' && p[i] == '1') {
          for (j = 1; j <= i; j++) {
            if (p[j] == '1')
              p[j] = '0';
            else
              p[j] = '1';
          }
          k = i;
          j = 0;
          while (j < k) {
            char c = p[j];
            p[j] = p[k];
            p[k] = c;
            j++;
            k--;
          }
          v.push_back(1);
          v.push_back(i + 1);
        } else if (p[0] == '1' && p[i] == '1') {
          for (j = 0; j <= i; j++) {
            if (p[j] == '1')
              p[j] = '0';
            else
              p[j] = '1';
          }
          k = i;
          j = 0;
          while (j < k) {
            char c = p[j];
            p[j] = p[k];
            p[k] = c;
            j++;
            k--;
          }
          v.push_back(i + 1);
        } else if (p[0] == '0' && p[i] == '0') {
          for (j = 0; j <= i; j++) {
            if (p[j] == '1')
              p[j] = '0';
            else
              p[j] = '1';
          }
          k = i;
          j = 0;
          while (j < k) {
            char c = p[j];
            p[j] = p[k];
            p[k] = c;
            j++;
            k--;
          }
          v.push_back(i + 1);
        } else {
          for (j = 1; j <= i; j++) {
            if (p[j] == '1')
              p[j] = '0';
            else
              p[j] = '1';
          }
          k = i;
          j = 0;
          while (j < k) {
            char c = p[j];
            p[j] = p[k];
            p[k] = c;
            j++;
            k--;
          }
          v.push_back(1);
          v.push_back(i + 1);
        }
      }
    }
    if (p[0] != q[0]) {
      v.push_back(1);
    }
    cout << v.size() << " ";
    for (i = 0; i < v.size(); i++) {
      cout << v[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
