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

class B:
    def __init__(self, txt: str):
        self.x: 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.s: D = None
        self.z: A = None
        self.txt = txt

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

e.r = i
g.x = e
k.r = i
i.s = b
i.z = e
b.s = i
b.z = e
j.x = e
assert k.r.s.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: 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.s: D = None
        self.z: A = None
        self.txt = txt

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

e.r = i
g.x = e
k.r = i
i.s = b
i.z = e
b.s = i
b.z = e
j.x = e
assert k.r.s.z.r.txt == "i"