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

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

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

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

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

c.y = m
b.q = n
b.w = m
m.t = b
n.q = m
n.p = c
assert n.q.t.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

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

c.y = m
b.q = n
b.w = m
m.t = b
n.q = m
n.p = c
assert n.q.t.q.q.txt == "m"