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

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

k = A("k")
i = B("i")
g = B("g")
e = B("e")
n = A("n")
f = A("f")
a = A("a")

k.r = g
i.u = g
g.u = i
e.u = i
n.r = g
f.r = i
a.r = i
assert i.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

k = A("k")
i = B("i")
g = B("g")
e = B("e")
n = A("n")
f = A("f")
a = A("a")

k.r = g
i.u = g
g.u = i
e.u = i
n.r = g
f.r = i
a.r = i
assert i.u.u.u.txt == "g"