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

class B:
    def __init__(self, txt: str):
        self.z: C = None
        self.w: D = None
        self.p: A = None
        self.t: A = None
        self.txt = txt

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

class D:
    def __init__(self, txt: str):
        self.o: B = None
        self.u: B = None
        self.w: B = None
        self.txt = txt

g = A("g")
f = B("f")
d = C("d")
m = D("m")
l = B("l")

g.v = d
f.z = d
f.w = m
f.p = g
f.t = g
d.r = g
d.w = m
m.o = f
m.w = f
m.u = l
l.z = d
l.w = m
l.p = g
l.t = g
assert m.u.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.z: C = None
        self.w: D = None
        self.p: A = None
        self.t: A = None
        self.txt = txt

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

class D:
    def __init__(self, txt: str):
        self.o: B = None
        self.u: B = None
        self.w: B = None
        self.txt = txt

g = A("g")
f = B("f")
d = C("d")
m = D("m")
l = B("l")

g.v = d
f.z = d
f.w = m
f.p = g
f.t = g
d.r = g
d.w = m
m.o = f
m.w = f
m.u = l
l.z = d
l.w = m
l.p = g
l.t = g
assert m.u.p.v.txt == "d"