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")
n = B("n")
d = A("d")
a = B("a")
j = A("j")
g = B("g")
b = A("b")
m = A("m")
k = A("k")
i = B("i")

f.t = j
n.r = m
d.t = j
a.r = d
j.t = k
g.r = m
b.t = k
m.t = f
k.t = m
i.r = k
assert g.r.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")
n = B("n")
d = A("d")
a = B("a")
j = A("j")
g = B("g")
b = A("b")
m = A("m")
k = A("k")
i = B("i")

f.t = j
n.r = m
d.t = j
a.r = d
j.t = k
g.r = m
b.t = k
m.t = f
k.t = m
i.r = k
assert g.r.t.t.t.t.t.txt == "f"