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

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

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

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

j = A("j")
c = B("c")
e = C("e")
b = D("b")
a = D("a")

j.z = e
c.x = a
e.r = c
b.q = a
b.x = j
b.w = j
a.q = b
a.x = j
a.w = j
assert a.x.z.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

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

j = A("j")
c = B("c")
e = C("e")
b = D("b")
a = D("a")

j.z = e
c.x = a
e.r = c
b.q = a
b.x = j
b.w = j
a.q = b
a.x = j
a.w = j
assert a.x.z.r.x.txt == "a"