class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.s: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

h = A("h")
m = B("m")
k = A("k")
f = B("f")

h.o = m
h.s = f
m.t = h
k.o = f
k.s = f
f.t = k
assert h.o.t.o.t.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.s: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

h = A("h")
m = B("m")
k = A("k")
f = B("f")

h.o = m
h.s = f
m.t = h
k.o = f
k.s = f
f.t = k
assert h.o.t.o.t.txt == "h"