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

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

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

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

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

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

m.p = k
m.o = e
k.y = m
e.p = k
e.o = m
n.y = m
assert m.p.y.p.txt == "k"