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

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

k = A("k")
e = B("e")
b = A("b")
g = B("g")
n = B("n")
h = B("h")

k.q = b
k.r = g
e.t = h
e.u = k
b.q = k
b.r = h
g.t = h
g.u = k
n.t = e
n.u = b
h.t = e
h.u = k
assert h.t.t.u.r.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.r: B = None
        self.txt = txt

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

k = A("k")
e = B("e")
b = A("b")
g = B("g")
n = B("n")
h = B("h")

k.q = b
k.r = g
e.t = h
e.u = k
b.q = k
b.r = h
g.t = h
g.u = k
n.t = e
n.u = b
h.t = e
h.u = k
assert h.t.t.u.r.u.r.txt == "g"