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

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

b = A("b")
i = B("i")
e = B("e")
g = A("g")
d = A("d")
j = B("j")
h = A("h")
k = B("k")
c = B("c")
l = A("l")

b.p = j
i.q = c
e.q = c
g.p = c
d.p = e
j.q = k
h.p = e
k.q = e
c.q = i
l.p = j
assert l.p.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

b = A("b")
i = B("i")
e = B("e")
g = A("g")
d = A("d")
j = B("j")
h = A("h")
k = B("k")
c = B("c")
l = A("l")

b.p = j
i.q = c
e.q = c
g.p = c
d.p = e
j.q = k
h.p = e
k.q = e
c.q = i
l.p = j
assert l.p.q.q.q.txt == "c"