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

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

j = A("j")
l = B("l")
m = A("m")
n = A("n")
h = A("h")
k = A("k")
g = B("g")
c = A("c")

j.x = l
j.r = k
l.t = j
l.q = g
m.x = l
m.r = c
n.x = g
n.r = c
h.x = l
h.r = m
k.x = l
k.r = c
g.t = c
g.q = l
c.x = l
c.r = m
assert h.r.x.q.t.x.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.r: A = None
        self.txt = txt

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

j = A("j")
l = B("l")
m = A("m")
n = A("n")
h = A("h")
k = A("k")
g = B("g")
c = A("c")

j.x = l
j.r = k
l.t = j
l.q = g
m.x = l
m.r = c
n.x = g
n.r = c
h.x = l
h.r = m
k.x = l
k.r = c
g.t = c
g.q = l
c.x = l
c.r = m
assert h.r.x.q.t.x.q.t.txt == "c"