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

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

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

i = A("i")
b = B("b")
n = C("n")
c = C("c")
g = B("g")
d = A("d")

i.v = d
i.r = c
b.t = d
n.r = c
n.z = d
c.r = n
c.z = d
g.t = d
d.v = i
d.r = n
assert g.t.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.r: C = None
        self.txt = txt

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

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

i = A("i")
b = B("b")
n = C("n")
c = C("c")
g = B("g")
d = A("d")

i.v = d
i.r = c
b.t = d
n.r = c
n.z = d
c.r = n
c.z = d
g.t = d
d.v = i
d.r = n
assert g.t.r.z.txt == "d"