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

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

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

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

g = A("g")
l = B("l")
e = C("e")
m = D("m")
b = A("b")

g.q = e
g.r = e
l.r = e
e.u = m
m.w = e
m.x = b
b.q = e
b.r = e
assert g.q.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.r: C = None
        self.txt = txt

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

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

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

g = A("g")
l = B("l")
e = C("e")
m = D("m")
b = A("b")

g.q = e
g.r = e
l.r = e
e.u = m
m.w = e
m.x = b
b.q = e
b.r = e
assert g.q.u.x.txt == "b"