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

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

k = A("k")
n = B("n")
h = B("h")
j = B("j")
m = A("m")
d = B("d")

k.t = d
k.r = m
n.w = d
n.v = h
h.w = j
h.v = j
j.w = d
j.v = n
m.t = n
m.r = k
d.w = n
d.v = h
assert n.w.v.w.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: A = None
        self.txt = txt

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

k = A("k")
n = B("n")
h = B("h")
j = B("j")
m = A("m")
d = B("d")

k.t = d
k.r = m
n.w = d
n.v = h
h.w = j
h.v = j
j.w = d
j.v = n
m.t = n
m.r = k
d.w = n
d.v = h
assert n.w.v.w.v.v.v.txt == "j"