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

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

n = A("n")
l = B("l")
f = B("f")
c = A("c")
g = B("g")

n.q = c
l.y = f
l.q = c
f.y = g
f.q = n
c.q = n
g.y = l
g.q = c
assert n.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.y: B = None
        self.q: A = None
        self.txt = txt

n = A("n")
l = B("l")
f = B("f")
c = A("c")
g = B("g")

n.q = c
l.y = f
l.q = c
f.y = g
f.q = n
c.q = n
g.y = l
g.q = c
assert n.q.q.q.q.txt == "n"