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

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

h = A("h")
k = B("k")
b = A("b")
e = B("e")
j = A("j")
i = A("i")

h.w = b
h.v = k
k.r = e
b.w = i
b.v = k
e.r = k
j.w = i
j.v = e
i.w = h
i.v = e
assert b.v.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.v: B = None
        self.txt = txt

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

h = A("h")
k = B("k")
b = A("b")
e = B("e")
j = A("j")
i = A("i")

h.w = b
h.v = k
k.r = e
b.w = i
b.v = k
e.r = k
j.w = i
j.v = e
i.w = h
i.v = e
assert b.v.r.r.r.txt == "e"