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

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

class C:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: D = None
        self.s: B = None
        self.z: D = None
        self.txt = txt

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

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

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

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

class C:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: D = None
        self.s: B = None
        self.z: D = None
        self.txt = txt

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

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

g.v = d
g.s = n
g.x = n
g.y = n
d.w = m
d.q = g
d.y = g
d.v = g
n.r = d
n.s = d
n.u = m
n.z = m
m.p = d
m.o = n
assert d.v.s.s.y.txt == "g"