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

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

b = A("b")
j = B("j")
l = A("l")
m = A("m")
d = B("d")
i = A("i")
c = B("c")
h = A("h")
f = B("f")

b.r = i
b.p = c
j.w = f
l.r = i
l.p = d
m.r = i
m.p = j
d.w = f
i.r = h
i.p = c
c.w = j
h.r = m
h.p = j
f.w = j
assert d.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.p: B = None
        self.txt = txt

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

b = A("b")
j = B("j")
l = A("l")
m = A("m")
d = B("d")
i = A("i")
c = B("c")
h = A("h")
f = B("f")

b.r = i
b.p = c
j.w = f
l.r = i
l.p = d
m.r = i
m.p = j
d.w = f
i.r = h
i.p = c
c.w = j
h.r = m
h.p = j
f.w = j
assert d.w.w.w.w.txt == "j"