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

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

l = A("l")
b = B("b")
j = A("j")
h = A("h")
m = A("m")
f = B("f")

l.q = j
b.u = f
b.o = h
j.q = m
h.q = l
m.q = h
f.u = b
f.o = h
assert h.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

l = A("l")
b = B("b")
j = A("j")
h = A("h")
m = A("m")
f = B("f")

l.q = j
b.u = f
b.o = h
j.q = m
h.q = l
m.q = h
f.u = b
f.o = h
assert h.q.q.q.q.q.q.txt == "j"