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

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

e = A("e")
m = B("m")
b = B("b")
k = A("k")
j = A("j")
n = B("n")
f = A("f")

e.x = k
m.q = b
b.q = n
k.x = f
j.x = e
n.q = m
f.x = k
assert f.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

e = A("e")
m = B("m")
b = B("b")
k = A("k")
j = A("j")
n = B("n")
f = A("f")

e.x = k
m.q = b
b.q = n
k.x = f
j.x = e
n.q = m
f.x = k
assert f.x.x.x.x.x.x.txt == "f"