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

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

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

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

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

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

m.x = k
c.p = k
n.x = c
k.p = c
assert n.x.p.p.p.txt == "k"