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

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

f = A("f")
e = B("e")
d = B("d")
m = B("m")
h = B("h")
k = B("k")
a = B("a")
g = A("g")

f.q = d
e.y = k
d.y = h
m.y = e
h.y = k
k.y = h
a.y = h
g.q = k
assert e.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

f = A("f")
e = B("e")
d = B("d")
m = B("m")
h = B("h")
k = B("k")
a = B("a")
g = A("g")

f.q = d
e.y = k
d.y = h
m.y = e
h.y = k
k.y = h
a.y = h
g.q = k
assert e.y.y.y.y.y.txt == "k"