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

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

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

c = A("c")
m = B("m")
n = C("n")
g = A("g")
d = C("d")

c.y = m
c.v = d
c.r = d
m.p = c
m.u = n
n.w = g
n.y = m
g.y = m
g.v = n
g.r = n
d.w = g
d.y = m
assert m.p.r.y.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.v: C = None
        self.r: C = None
        self.txt = txt

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

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

c = A("c")
m = B("m")
n = C("n")
g = A("g")
d = C("d")

c.y = m
c.v = d
c.r = d
m.p = c
m.u = n
n.w = g
n.y = m
g.y = m
g.v = n
g.r = n
d.w = g
d.y = m
assert m.p.r.y.p.y.txt == "m"