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

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

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

k.q = f
b.r = d
b.u = c
c.q = j
j.q = k
f.q = k
n.r = g
n.u = c
l.r = d
l.u = k
d.r = n
d.u = c
g.r = l
g.u = j
assert d.r.r.u.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.r: B = None
        self.u: A = None
        self.txt = txt

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

k.q = f
b.r = d
b.u = c
c.q = j
j.q = k
f.q = k
n.r = g
n.u = c
l.r = d
l.u = k
d.r = n
d.u = c
g.r = l
g.u = j
assert d.r.r.u.q.q.txt == "f"