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

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

h = A("h")
j = B("j")
c = B("c")

h.w = j
j.p = c
j.y = h
c.p = j
c.y = h
assert h.w.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

h = A("h")
j = B("j")
c = B("c")

h.w = j
j.p = c
j.y = h
c.p = j
c.y = h
assert h.w.y.w.txt == "j"