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

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

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

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

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

m.q = b
g.w = m
g.z = m
e.p = b
b.t = g
b.w = e
assert g.w.q.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

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

m.q = b
g.w = m
g.z = m
e.p = b
b.t = g
b.w = e
assert g.w.q.w.p.txt == "b"