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

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

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

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

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

c.p = m
c.r = m
m.q = g
g.z = c
g.w = b
g.u = m
b.x = c
b.w = g
b.r = g
assert m.q.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.r: B = None
        self.txt = txt

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

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

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

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

c.p = m
c.r = m
m.q = g
g.z = c
g.w = b
g.u = m
b.x = c
b.w = g
b.r = g
assert m.q.z.p.txt == "m"