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

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

d = A("d")
j = B("j")
i = B("i")
c = B("c")
b = B("b")
m = A("m")

d.q = b
j.y = m
i.y = d
c.y = m
b.y = d
m.q = b
assert m.q.y.q.y.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

d = A("d")
j = B("j")
i = B("i")
c = B("c")
b = B("b")
m = A("m")

d.q = b
j.y = m
i.y = d
c.y = m
b.y = d
m.q = b
assert m.q.y.q.y.q.y.txt == "d"