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

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

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

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

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

i.s = g
h.z = g
h.r = j
g.y = i
f.u = j
j.z = g
j.r = h
assert j.z.y.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

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

i.s = g
h.z = g
h.r = j
g.y = i
f.u = j
j.z = g
j.r = h
assert j.z.y.s.y.txt == "i"