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

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

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

h = A("h")
a = B("a")
k = C("k")
c = B("c")
m = C("m")
d = B("d")
b = B("b")
f = C("f")
e = C("e")
i = A("i")

h.q = b
a.q = b
a.x = i
k.r = c
c.q = a
c.x = h
m.r = c
d.q = a
d.x = i
b.q = d
b.x = h
f.r = a
e.r = d
i.q = b
assert b.x.q.x.q.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
k = C("k")
c = B("c")
m = C("m")
d = B("d")
b = B("b")
f = C("f")
e = C("e")
i = A("i")

h.q = b
a.q = b
a.x = i
k.r = c
c.q = a
c.x = h
m.r = c
d.q = a
d.x = i
b.q = d
b.x = h
f.r = a
e.r = d
i.q = b
assert b.x.q.x.q.x.q.txt == "b"