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

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

c = A("c")
f = B("f")
m = A("m")
a = B("a")
k = A("k")
g = B("g")
h = B("h")
b = B("b")

c.r = g
f.t = c
m.r = g
a.t = k
k.r = a
g.t = k
h.t = c
b.t = m
assert h.t.r.t.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

c = A("c")
f = B("f")
m = A("m")
a = B("a")
k = A("k")
g = B("g")
h = B("h")
b = B("b")

c.r = g
f.t = c
m.r = g
a.t = k
k.r = a
g.t = k
h.t = c
b.t = m
assert h.t.r.t.r.t.r.txt == "a"