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

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

a = A("a")
j = B("j")
f = B("f")
g = A("g")
k = A("k")
c = B("c")
h = A("h")
e = B("e")
n = A("n")

a.u = g
a.r = n
j.q = k
f.q = h
g.u = k
g.r = h
k.u = n
k.r = n
c.q = k
h.u = k
h.r = g
e.q = h
n.u = g
n.r = g
assert k.r.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.r: A = None
        self.txt = txt

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

a = A("a")
j = B("j")
f = B("f")
g = A("g")
k = A("k")
c = B("c")
h = A("h")
e = B("e")
n = A("n")

a.u = g
a.r = n
j.q = k
f.q = h
g.u = k
g.r = h
k.u = n
k.r = n
c.q = k
h.u = k
h.r = g
e.q = h
n.u = g
n.r = g
assert k.r.u.r.txt == "h"