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

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

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

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

b = A("b")
g = B("g")
n = C("n")
m = D("m")
i = B("i")

b.z = n
g.p = n
g.v = b
g.y = b
g.s = b
n.t = g
n.z = m
n.u = m
n.p = b
m.z = n
m.y = n
m.t = b
i.p = n
i.v = b
i.y = b
i.s = b
assert n.u.y.t.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

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

b = A("b")
g = B("g")
n = C("n")
m = D("m")
i = B("i")

b.z = n
g.p = n
g.v = b
g.y = b
g.s = b
n.t = g
n.z = m
n.u = m
n.p = b
m.z = n
m.y = n
m.t = b
i.p = n
i.v = b
i.y = b
i.s = b
assert n.u.y.t.txt == "g"