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

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

b = A("b")
a = B("a")
e = B("e")
l = B("l")
d = A("d")
n = B("n")
g = B("g")
c = B("c")
k = A("k")
f = A("f")

b.q = f
a.q = f
e.q = k
l.q = b
d.q = b
n.q = d
g.q = f
c.q = k
k.q = b
f.q = b
assert k.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

b = A("b")
a = B("a")
e = B("e")
l = B("l")
d = A("d")
n = B("n")
g = B("g")
c = B("c")
k = A("k")
f = A("f")

b.q = f
a.q = f
e.q = k
l.q = b
d.q = b
n.q = d
g.q = f
c.q = k
k.q = b
f.q = b
assert k.q.q.q.q.txt == "f"