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

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

i = A("i")
k = B("k")
c = A("c")
b = B("b")
h = B("h")
e = A("e")
g = B("g")

i.p = e
k.w = i
c.p = i
b.w = c
h.w = e
e.p = c
g.w = c
assert k.w.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

i = A("i")
k = B("k")
c = A("c")
b = B("b")
h = B("h")
e = A("e")
g = B("g")

i.p = e
k.w = i
c.p = i
b.w = c
h.w = e
e.p = c
g.w = c
assert k.w.p.p.p.p.p.p.txt == "i"