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

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

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

c.p = l
c.q = n
n.p = l
n.y = l
f.p = c
f.y = c
b.p = l
b.y = l
l.p = c
l.q = b
assert c.p.p.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.q: B = None
        self.txt = txt

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

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

c.p = l
c.q = n
n.p = l
n.y = l
f.p = c
f.y = c
b.p = l
b.y = l
l.p = c
l.q = b
assert c.p.p.q.p.txt == "l"