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

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

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

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

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

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

g.y = h
j.q = c
h.y = g
c.q = j
m.q = c
a.q = j
assert j.q.q.q.q.q.q.txt == "j"