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

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

k = A("k")
c = B("c")
e = B("e")
f = A("f")
g = B("g")
a = A("a")
b = A("b")

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

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

k = A("k")
c = B("c")
e = B("e")
f = A("f")
g = B("g")
a = A("a")
b = A("b")

k.p = b
k.y = f
c.w = f
e.w = k
f.p = a
f.y = b
g.w = b
a.p = b
a.y = b
b.p = f
b.y = k
assert c.w.y.p.p.y.y.txt == "k"