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

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

h = A("h")
k = B("k")
m = B("m")
f = A("f")
b = B("b")
a = B("a")
i = A("i")
j = A("j")

h.x = f
k.q = h
k.o = m
m.q = i
m.o = k
f.x = j
b.q = h
b.o = m
a.q = f
a.o = b
i.x = j
j.x = f
assert a.o.q.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

h = A("h")
k = B("k")
m = B("m")
f = A("f")
b = B("b")
a = B("a")
i = A("i")
j = A("j")

h.x = f
k.q = h
k.o = m
m.q = i
m.o = k
f.x = j
b.q = h
b.o = m
a.q = f
a.o = b
i.x = j
j.x = f
assert a.o.q.x.x.x.x.x.txt == "f"