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

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

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

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

g = A("g")
n = B("n")
l = C("l")
m = D("m")
e = D("e")

g.z = l
n.w = l
l.v = g
m.w = e
m.v = g
m.z = n
e.w = m
e.v = g
e.z = n
assert m.z.w.v.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

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

g = A("g")
n = B("n")
l = C("l")
m = D("m")
e = D("e")

g.z = l
n.w = l
l.v = g
m.w = e
m.v = g
m.z = n
e.w = m
e.v = g
e.z = n
assert m.z.w.v.z.v.txt == "g"