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

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

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

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

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

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

e.x = h
e.p = g
h.p = g
h.u = e
g.x = h
g.p = e
assert h.u.x.p.txt == "g"