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

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

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

g.o = i
f.q = e
h.q = n
i.q = n
n.q = f
e.q = i
l.o = h
k.o = e
assert g.o.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

g.o = i
f.q = e
h.q = n
i.q = n
n.q = f
e.q = i
l.o = h
k.o = e
assert g.o.q.q.txt == "f"