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

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

d = A("d")
l = B("l")
m = A("m")
a = B("a")

d.y = m
d.q = l
l.w = m
l.p = a
m.y = d
m.q = l
a.w = m
a.p = l
assert m.y.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.q: B = None
        self.txt = txt

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

d = A("d")
l = B("l")
m = A("m")
a = B("a")

d.y = m
d.q = l
l.w = m
l.p = a
m.y = d
m.q = l
a.w = m
a.p = l
assert m.y.y.q.txt == "l"