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

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

g = A("g")
h = B("h")
f = B("f")
b = A("b")
e = B("e")
k = B("k")

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

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

g = A("g")
h = B("h")
f = B("f")
b = A("b")
e = B("e")
k = B("k")

g.w = f
g.p = b
h.w = g
h.x = e
f.w = g
f.x = e
b.w = k
b.p = g
e.w = g
e.x = k
k.w = b
k.x = f
assert e.w.w.w.p.txt == "b"