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

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

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

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

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

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

g.p = c
g.w = j
h.w = c
h.x = g
j.p = h
j.w = g
c.w = h
c.x = j
assert c.w.w.w.txt == "h"