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

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

d = A("d")
i = B("i")
b = B("b")
l = A("l")
e = B("e")
h = B("h")

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

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

d = A("d")
i = B("i")
b = B("b")
l = A("l")
e = B("e")
h = B("h")

d.r = h
d.p = l
i.p = d
i.t = h
b.p = l
b.t = i
l.r = e
l.p = d
e.p = d
e.t = h
h.p = l
h.t = b
assert e.p.p.p.txt == "d"