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

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

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

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

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

j.x = d
j.u = d
j.v = d
j.s = g
g.w = h
g.x = f
f.o = j
f.v = h
d.s = g
h.o = j
h.v = f
assert f.o.s.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.s: B = None
        self.u: D = None
        self.v: D = None
        self.txt = txt

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

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

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

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

j.x = d
j.u = d
j.v = d
j.s = g
g.w = h
g.x = f
f.o = j
f.v = h
d.s = g
h.o = j
h.v = f
assert f.o.s.x.o.x.txt == "d"