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

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

e = A("e")
n = B("n")
k = A("k")
f = B("f")

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

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

e = A("e")
n = B("n")
k = A("k")
f = B("f")

e.y = n
e.p = n
n.q = e
k.y = n
k.p = f
f.q = e
assert f.q.p.q.y.txt == "n"