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

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

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

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

a = A("a")
k = B("k")
b = C("b")
f = D("f")
g = B("g")
i = B("i")
m = B("m")
h = D("h")

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

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

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

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

a = A("a")
k = B("k")
b = C("b")
f = D("f")
g = B("g")
i = B("i")
m = B("m")
h = D("h")

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