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

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

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

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

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

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

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