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

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

c = A("c")
e = B("e")
b = A("b")
f = B("f")
a = A("a")
h = A("h")

c.u = e
c.p = e
e.w = c
b.u = e
b.p = e
f.w = a
a.u = f
a.p = f
h.u = e
h.p = f
assert e.w.u.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.p: B = None
        self.txt = txt

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

c = A("c")
e = B("e")
b = A("b")
f = B("f")
a = A("a")
h = A("h")

c.u = e
c.p = e
e.w = c
b.u = e
b.p = e
f.w = a
a.u = f
a.p = f
h.u = e
h.p = f
assert e.w.u.w.p.txt == "e"