class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.v: A = 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.p: C = None
        self.txt = txt

g = A("g")
b = B("b")
m = C("m")
i = C("i")
e = C("e")
k = A("k")

g.z = m
g.v = k
b.t = k
m.p = e
i.p = m
e.p = i
k.z = e
k.v = g
assert g.v.z.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.v: A = 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.p: C = None
        self.txt = txt

g = A("g")
b = B("b")
m = C("m")
i = C("i")
e = C("e")
k = A("k")

g.z = m
g.v = k
b.t = k
m.p = e
i.p = m
e.p = i
k.z = e
k.v = g
assert g.v.z.p.p.p.txt == "e"