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.t: B = None
        self.txt = txt

h = A("h")
c = B("c")
g = B("g")
n = B("n")
k = A("k")
m = B("m")
l = B("l")

h.v = l
h.r = k
c.t = g
g.t = m
n.t = l
k.v = l
k.r = h
m.t = g
l.t = n
assert m.t.t.t.t.t.t.t.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.t: B = None
        self.txt = txt

h = A("h")
c = B("c")
g = B("g")
n = B("n")
k = A("k")
m = B("m")
l = B("l")

h.v = l
h.r = k
c.t = g
g.t = m
n.t = l
k.v = l
k.r = h
m.t = g
l.t = n
assert m.t.t.t.t.t.t.t.txt == "g"