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

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

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

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

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

d.q = a
n.u = d
n.x = d
n.q = e
n.t = e
a.x = e
e.y = d
assert e.y.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

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

d.q = a
n.u = d
n.x = d
n.q = e
n.t = e
a.x = e
e.y = d
assert e.y.q.x.txt == "e"