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

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

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

f.t = a
f.q = i
e.p = a
e.x = j
i.p = g
i.x = j
j.p = h
j.x = c
k.p = f
k.x = j
g.t = a
g.q = c
a.t = f
a.q = k
h.t = a
h.q = k
c.p = a
c.x = k
assert c.p.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.q: B = None
        self.txt = txt

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

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

f.t = a
f.q = i
e.p = a
e.x = j
i.p = g
i.x = j
j.p = h
j.x = c
k.p = f
k.x = j
g.t = a
g.q = c
a.t = f
a.q = k
h.t = a
h.q = k
c.p = a
c.x = k
assert c.p.t.t.txt == "a"