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

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

d = A("d")
f = B("f")
e = A("e")
b = A("b")
g = B("g")
j = A("j")
l = B("l")
a = B("a")
m = A("m")
c = B("c")

d.q = f
f.u = d
e.q = f
b.q = l
g.u = b
j.q = g
l.u = m
a.u = j
m.q = l
c.u = d
assert d.q.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

d = A("d")
f = B("f")
e = A("e")
b = A("b")
g = B("g")
j = A("j")
l = B("l")
a = B("a")
m = A("m")
c = B("c")

d.q = f
f.u = d
e.q = f
b.q = l
g.u = b
j.q = g
l.u = m
a.u = j
m.q = l
c.u = d
assert d.q.u.q.txt == "f"