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

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

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

f = A("f")
g = B("g")
e = C("e")
d = C("d")
l = C("l")
a = A("a")
i = B("i")
k = A("k")

f.q = e
g.z = d
g.w = k
g.q = a
e.p = i
e.r = i
d.p = i
d.r = i
l.p = g
l.r = g
a.q = d
i.z = d
i.w = k
i.q = k
k.q = l
assert i.z.p.q.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

f = A("f")
g = B("g")
e = C("e")
d = C("d")
l = C("l")
a = A("a")
i = B("i")
k = A("k")

f.q = e
g.z = d
g.w = k
g.q = a
e.p = i
e.r = i
d.p = i
d.r = i
l.p = g
l.r = g
a.q = d
i.z = d
i.w = k
i.q = k
k.q = l
assert i.z.p.q.q.r.txt == "g"