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

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

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

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

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

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

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

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

i.z = d
i.q = a
f.r = c
f.p = a
c.x = d
a.x = d
d.r = a
d.p = a
b.z = d
b.q = a
k.z = f
k.q = c
l.z = f
l.q = c
h.z = f
h.q = a
assert k.q.x.p.x.p.txt == "a"