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

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

k = A("k")
i = B("i")
c = A("c")
g = B("g")
d = A("d")
n = B("n")

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

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

k = A("k")
i = B("i")
c = A("c")
g = B("g")
d = A("d")
n = B("n")

k.x = i
i.w = c
i.p = k
c.x = i
g.w = c
g.p = k
d.x = i
n.w = k
n.p = d
assert k.x.w.x.txt == "i"