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

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

g = A("g")
h = B("h")
l = B("l")
n = A("n")
c = A("c")
f = A("f")

g.r = n
g.w = f
h.w = f
l.w = c
n.r = g
n.w = f
c.r = n
c.w = g
f.r = g
f.w = c
assert f.w.w.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.w: A = None
        self.txt = txt

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

g = A("g")
h = B("h")
l = B("l")
n = A("n")
c = A("c")
f = A("f")

g.r = n
g.w = f
h.w = f
l.w = c
n.r = g
n.w = f
c.r = n
c.w = g
f.r = g
f.w = c
assert f.w.w.w.r.txt == "g"