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

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

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

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

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

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

g.r = e
h.w = c
h.p = c
c.w = h
c.p = h
j.r = g
e.r = g
assert c.p.w.w.w.p.txt == "h"