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

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

class C:
    def __init__(self, txt: str):
        self.x: B = None
        self.v: E = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.p: A = None
        self.y: E = None
        self.txt = txt

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

a = A("a")
j = B("j")
h = C("h")
f = D("f")
b = E("b")

a.x = f
j.r = b
h.x = j
h.v = b
f.p = a
f.y = b
b.r = a
b.z = a
b.s = j
assert j.r.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.x: B = None
        self.v: E = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.p: A = None
        self.y: E = None
        self.txt = txt

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

a = A("a")
j = B("j")
h = C("h")
f = D("f")
b = E("b")

a.x = f
j.r = b
h.x = j
h.v = b
f.p = a
f.y = b
b.r = a
b.z = a
b.s = j
assert j.r.s.r.txt == "b"