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.u: B = None
        self.w: B = None
        self.txt = txt

d = A("d")
f = B("f")
i = B("i")
g = A("g")
l = B("l")
e = A("e")
j = B("j")
b = A("b")

d.r = b
d.w = g
f.u = l
f.w = i
i.u = j
i.w = l
g.r = e
g.w = e
l.u = i
l.w = i
e.r = d
e.w = d
j.u = f
j.w = i
b.r = e
b.w = e
assert j.u.u.w.u.u.u.w.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.u: B = None
        self.w: B = None
        self.txt = txt

d = A("d")
f = B("f")
i = B("i")
g = A("g")
l = B("l")
e = A("e")
j = B("j")
b = A("b")

d.r = b
d.w = g
f.u = l
f.w = i
i.u = j
i.w = l
g.r = e
g.w = e
l.u = i
l.w = i
e.r = d
e.w = d
j.u = f
j.w = i
b.r = e
b.w = e
assert j.u.u.w.u.u.u.w.txt == "i"