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

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

j = A("j")
k = B("k")
m = A("m")
e = A("e")
f = B("f")
n = B("n")
h = B("h")

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

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

j = A("j")
k = B("k")
m = A("m")
e = A("e")
f = B("f")
n = B("n")
h = B("h")

j.r = k
j.w = m
k.u = h
m.r = h
m.w = e
e.r = h
e.w = m
f.u = k
n.u = f
h.u = k
assert f.u.u.u.u.u.u.u.txt == "k"