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

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

e = A("e")
l = B("l")
j = A("j")
h = B("h")
k = B("k")
a = B("a")
d = A("d")

e.p = l
l.t = j
l.r = d
j.p = l
h.t = e
h.r = j
k.t = e
k.r = e
a.t = e
a.r = d
d.p = k
assert k.r.p.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

e = A("e")
l = B("l")
j = A("j")
h = B("h")
k = B("k")
a = B("a")
d = A("d")

e.p = l
l.t = j
l.r = d
j.p = l
h.t = e
h.r = j
k.t = e
k.r = e
a.t = e
a.r = d
d.p = k
assert k.r.p.r.p.r.txt == "e"