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

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

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

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

j = A("j")
k = B("k")
d = C("d")
m = D("m")
g = B("g")
h = A("h")
c = A("c")

j.p = m
k.o = d
k.s = d
d.t = j
d.u = g
m.x = h
g.o = d
g.s = d
h.p = m
c.p = m
assert g.s.t.p.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

j = A("j")
k = B("k")
d = C("d")
m = D("m")
g = B("g")
h = A("h")
c = A("c")

j.p = m
k.o = d
k.s = d
d.t = j
d.u = g
m.x = h
g.o = d
g.s = d
h.p = m
c.p = m
assert g.s.t.p.x.p.txt == "m"