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

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

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

g = A("g")
f = B("f")
i = C("i")
c = A("c")
m = C("m")

g.y = c
f.y = m
f.t = m
f.v = g
i.z = m
c.y = g
m.z = i
assert f.v.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

g = A("g")
f = B("f")
i = C("i")
c = A("c")
m = C("m")

g.y = c
f.y = m
f.t = m
f.v = g
i.z = m
c.y = g
m.z = i
assert f.v.y.y.y.y.txt == "g"