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

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

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

b = A("b")
k = B("k")
m = C("m")
d = C("d")
j = A("j")

b.t = k
b.r = d
k.v = b
k.r = m
m.z = d
m.q = k
m.t = k
d.z = m
d.q = k
d.t = k
j.t = k
j.r = m
assert b.r.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: C = None
        self.txt = txt

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

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

b = A("b")
k = B("k")
m = C("m")
d = C("d")
j = A("j")

b.t = k
b.r = d
k.v = b
k.r = m
m.z = d
m.q = k
m.t = k
d.z = m
d.q = k
d.t = k
j.t = k
j.r = m
assert b.r.z.z.txt == "d"