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

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

f = A("f")
m = B("m")
e = B("e")
k = A("k")
h = B("h")
l = A("l")
b = A("b")
j = B("j")
a = A("a")

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

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

f = A("f")
m = B("m")
e = B("e")
k = A("k")
h = B("h")
l = A("l")
b = A("b")
j = B("j")
a = A("a")

f.t = l
m.r = b
e.r = k
k.t = b
h.r = b
l.t = f
b.t = f
j.r = b
a.t = k
assert a.t.t.t.t.t.txt == "f"