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

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

g = A("g")
m = B("m")
b = A("b")
f = A("f")
a = A("a")
k = B("k")
j = A("j")
i = B("i")
e = B("e")

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

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

g = A("g")
m = B("m")
b = A("b")
f = A("f")
a = A("a")
k = B("k")
j = A("j")
i = B("i")
e = B("e")

g.r = j
m.r = g
b.r = j
f.r = a
a.r = b
k.r = a
j.r = f
i.r = g
e.r = a
assert k.r.r.r.r.r.r.r.txt == "j"