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

class B:
    def __init__(self, txt: str):
        self.v: C = None
        self.x: B = None
        self.y: C = None
        self.p: D = None
        self.txt = txt

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

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

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

m.r = l
c.v = n
c.x = i
c.y = l
c.p = g
n.o = m
n.r = m
n.w = l
f.p = m
f.u = g
l.o = m
l.r = m
l.w = n
i.v = l
i.y = l
i.x = c
i.p = g
g.p = m
g.u = f
assert n.w.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.v: C = None
        self.x: B = None
        self.y: C = None
        self.p: D = None
        self.txt = txt

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

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

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

m.r = l
c.v = n
c.x = i
c.y = l
c.p = g
n.o = m
n.r = m
n.w = l
f.p = m
f.u = g
l.o = m
l.r = m
l.w = n
i.v = l
i.y = l
i.x = c
i.p = g
g.p = m
g.u = f
assert n.w.r.r.txt == "l"