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

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

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

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

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

j.x = d
c.y = h
c.o = j
c.p = j
c.z = j
g.o = j
g.x = j
g.y = h
h.s = g
d.y = h
d.o = j
d.p = j
d.z = j
assert j.x.p.x.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

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

j.x = d
c.y = h
c.o = j
c.p = j
c.z = j
g.o = j
g.x = j
g.y = h
h.s = g
d.y = h
d.o = j
d.p = j
d.z = j
assert j.x.p.x.z.x.txt == "d"