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

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

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

f.t = g
f.q = c
b.r = f
l.r = j
c.r = n
n.t = c
n.q = c
g.r = f
j.t = b
j.q = g
i.t = b
i.q = g
assert j.t.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: B = None
        self.txt = txt

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

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

f.t = g
f.q = c
b.r = f
l.r = j
c.r = n
n.t = c
n.q = c
g.r = f
j.t = b
j.q = g
i.t = b
i.q = g
assert j.t.r.t.r.txt == "f"