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

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

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

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

e = A("e")
b = B("b")
d = C("d")
c = D("c")
a = D("a")
f = A("f")
g = D("g")

e.s = d
b.z = f
d.y = f
d.w = e
c.t = d
a.t = d
f.s = d
g.t = d
assert g.t.y.s.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

e = A("e")
b = B("b")
d = C("d")
c = D("c")
a = D("a")
f = A("f")
g = D("g")

e.s = d
b.z = f
d.y = f
d.w = e
c.t = d
a.t = d
f.s = d
g.t = d
assert g.t.y.s.y.s.txt == "d"