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

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

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

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

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

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

k.v = f
k.r = a
e.y = a
f.y = h
n.y = h
h.v = b
h.r = k
a.v = n
a.r = j
b.y = k
c.v = f
c.r = j
i.v = n
i.r = k
j.v = b
j.r = i
assert j.v.y.v.txt == "f"