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

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

e = A("e")
h = B("h")
f = A("f")

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

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

e = A("e")
h = B("h")
f = A("f")

e.v = h
e.u = f
h.p = e
f.v = h
f.u = e
assert f.u.v.p.txt == "e"