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

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

j = A("j")
h = B("h")
n = B("n")
b = A("b")
c = B("c")
i = A("i")
k = A("k")
f = B("f")

j.y = k
j.w = b
h.r = c
h.t = n
n.r = h
n.t = f
b.y = j
b.w = j
c.r = h
c.t = h
i.y = j
i.w = j
k.y = j
k.w = j
f.r = n
f.t = h
assert j.y.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.w: A = None
        self.txt = txt

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

j = A("j")
h = B("h")
n = B("n")
b = A("b")
c = B("c")
i = A("i")
k = A("k")
f = B("f")

j.y = k
j.w = b
h.r = c
h.t = n
n.r = h
n.t = f
b.y = j
b.w = j
c.r = h
c.t = h
i.y = j
i.w = j
k.y = j
k.w = j
f.r = n
f.t = h
assert j.y.y.w.txt == "b"