class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: B = None
        self.u: B = None
        self.w: D = 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.q: D = None
        self.x: B = None
        self.txt = txt

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

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

g.t = c
g.q = c
g.u = c
g.w = d
c.x = d
n.q = d
n.x = c
d.p = g
assert n.q.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: B = None
        self.u: B = None
        self.w: D = 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.q: D = None
        self.x: B = None
        self.txt = txt

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

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

g.t = c
g.q = c
g.u = c
g.w = d
c.x = d
n.q = d
n.x = c
d.p = g
assert n.q.p.w.txt == "d"