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

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

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

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

f = A("f")
g = B("g")
b = C("b")
d = D("d")
n = C("n")
c = B("c")
h = A("h")

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

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

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

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

f = A("f")
g = B("g")
b = C("b")
d = D("d")
n = C("n")
c = B("c")
h = A("h")

f.z = g
g.s = d
g.o = n
b.y = d
d.s = g
n.y = d
c.s = d
c.o = b
h.z = c
assert b.y.s.s.txt == "d"