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

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

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

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

e = A("e")
j = B("j")
b = C("b")
d = D("d")

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

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

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

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

e = A("e")
j = B("j")
b = C("b")
d = D("d")

e.q = d
j.s = b
b.x = j
b.r = j
b.z = j
b.v = d
d.v = e
d.z = b
d.x = b
assert j.s.v.z.txt == "b"