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

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

m = A("m")
a = B("a")
c = A("c")
b = A("b")
f = B("f")
j = A("j")
n = A("n")

m.q = j
a.x = m
a.y = b
c.q = m
b.q = n
f.x = b
f.y = m
j.q = n
n.q = c
assert j.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

m = A("m")
a = B("a")
c = A("c")
b = A("b")
f = B("f")
j = A("j")
n = A("n")

m.q = j
a.x = m
a.y = b
c.q = m
b.q = n
f.x = b
f.y = m
j.q = n
n.q = c
assert j.q.q.q.q.q.txt == "n"