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

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

g = A("g")
a = B("a")
m = B("m")
j = B("j")
c = B("c")
k = A("k")

g.z = k
g.o = k
a.q = m
m.q = a
j.q = m
c.q = a
k.z = g
k.o = g
assert j.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.o: A = None
        self.txt = txt

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

g = A("g")
a = B("a")
m = B("m")
j = B("j")
c = B("c")
k = A("k")

g.z = k
g.o = k
a.q = m
m.q = a
j.q = m
c.q = a
k.z = g
k.o = g
assert j.q.q.q.q.txt == "a"