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

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

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

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

i = A("i")
h = B("h")
b = C("b")
e = D("e")
g = B("g")

i.s = h
h.p = i
b.r = e
e.z = b
e.u = b
e.t = g
g.p = i
assert i.s.p.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

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

i = A("i")
h = B("h")
b = C("b")
e = D("e")
g = B("g")

i.s = h
h.p = i
b.r = e
e.z = b
e.u = b
e.t = g
g.p = i
assert i.s.p.s.p.s.txt == "h"