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

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

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

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

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

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

j.q = l
h.u = j
h.x = b
g.u = j
g.x = b
f.u = j
f.x = j
l.q = b
b.q = j
k.u = l
k.x = b
c.u = j
c.x = b
assert g.u.q.q.q.txt == "j"