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

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

e = A("e")
d = B("d")
c = C("c")
n = D("n")

e.r = n
e.s = n
e.q = c
e.x = c
d.p = e
c.q = n
n.z = d
n.x = d
n.q = e
assert c.q.x.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.q: C = None
        self.s: D = None
        self.x: C = 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.q: D = None
        self.txt = txt

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

e = A("e")
d = B("d")
c = C("c")
n = D("n")

e.r = n
e.s = n
e.q = c
e.x = c
d.p = e
c.q = n
n.z = d
n.x = d
n.q = e
assert c.q.x.p.q.txt == "c"