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

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

b = A("b")
f = B("f")
h = B("h")
g = B("g")
a = B("a")
d = B("d")
c = B("c")
m = A("m")

b.q = m
b.w = f
f.o = c
h.o = g
g.o = d
a.o = d
d.o = a
c.o = h
m.q = b
m.w = h
assert h.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.w: B = None
        self.txt = txt

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

b = A("b")
f = B("f")
h = B("h")
g = B("g")
a = B("a")
d = B("d")
c = B("c")
m = A("m")

b.q = m
b.w = f
f.o = c
h.o = g
g.o = d
a.o = d
d.o = a
c.o = h
m.q = b
m.w = h
assert h.o.o.o.txt == "a"