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

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

j = A("j")
k = B("k")
b = A("b")
h = B("h")
f = B("f")
g = B("g")

j.x = b
j.t = g
k.q = h
b.x = j
b.t = h
h.q = f
f.q = g
g.q = k
assert g.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.t: B = None
        self.txt = txt

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

j = A("j")
k = B("k")
b = A("b")
h = B("h")
f = B("f")
g = B("g")

j.x = b
j.t = g
k.q = h
b.x = j
b.t = h
h.q = f
f.q = g
g.q = k
assert g.q.q.q.q.q.txt == "k"