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

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

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

class D:
    def __init__(self, txt: str):
        self.y: B = None
        self.z: A = None
        self.o: B = None
        self.s: B = None
        self.txt = txt

a = A("a")
j = B("j")
h = C("h")
g = D("g")
m = B("m")
n = B("n")

a.s = h
a.p = h
a.z = g
j.t = g
j.z = a
j.x = n
h.s = a
g.y = m
g.z = a
g.o = n
g.s = n
m.t = g
m.z = a
m.x = n
n.t = g
n.z = a
n.x = j
assert m.x.x.z.s.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.p: C = None
        self.z: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.y: B = None
        self.z: A = None
        self.o: B = None
        self.s: B = None
        self.txt = txt

a = A("a")
j = B("j")
h = C("h")
g = D("g")
m = B("m")
n = B("n")

a.s = h
a.p = h
a.z = g
j.t = g
j.z = a
j.x = n
h.s = a
g.y = m
g.z = a
g.o = n
g.s = n
m.t = g
m.z = a
m.x = n
n.t = g
n.z = a
n.x = j
assert m.x.x.z.s.s.z.txt == "g"