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

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

j = A("j")
a = B("a")
k = A("k")
e = B("e")
c = B("c")
m = A("m")
b = A("b")
g = A("g")

j.t = k
j.p = e
a.y = c
k.t = g
k.p = e
e.y = c
c.y = e
m.t = k
m.p = e
b.t = m
b.p = a
g.t = k
g.p = a
assert m.t.p.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.p: B = None
        self.txt = txt

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

j = A("j")
a = B("a")
k = A("k")
e = B("e")
c = B("c")
m = A("m")
b = A("b")
g = A("g")

j.t = k
j.p = e
a.y = c
k.t = g
k.p = e
e.y = c
c.y = e
m.t = k
m.p = e
b.t = m
b.p = a
g.t = k
g.p = a
assert m.t.p.y.y.txt == "e"