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

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

e = A("e")
h = B("h")
j = B("j")
c = A("c")
k = A("k")
l = B("l")
i = A("i")
m = B("m")

e.v = i
h.r = j
h.y = m
j.r = h
j.y = h
c.v = i
k.v = e
l.r = h
l.y = j
i.v = k
m.r = l
m.y = h
assert c.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

e = A("e")
h = B("h")
j = B("j")
c = A("c")
k = A("k")
l = B("l")
i = A("i")
m = B("m")

e.v = i
h.r = j
h.y = m
j.r = h
j.y = h
c.v = i
k.v = e
l.r = h
l.y = j
i.v = k
m.r = l
m.y = h
assert c.v.v.v.txt == "e"