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

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

f = A("f")
d = B("d")
h = B("h")
j = A("j")
c = B("c")
g = B("g")
e = B("e")
n = A("n")
l = B("l")

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

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

f = A("f")
d = B("d")
h = B("h")
j = A("j")
c = B("c")
g = B("g")
e = B("e")
n = A("n")
l = B("l")

f.x = d
d.t = c
d.q = j
h.t = d
h.q = f
j.x = e
c.t = g
c.q = j
g.t = d
g.q = n
e.t = l
e.q = j
n.x = d
l.t = h
l.q = j
assert d.t.t.t.txt == "d"