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

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

n = A("n")
i = B("i")
a = B("a")
b = A("b")
g = B("g")
k = B("k")
l = A("l")
h = A("h")
e = B("e")
d = A("d")

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

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

n = A("n")
i = B("i")
a = B("a")
b = A("b")
g = B("g")
k = B("k")
l = A("l")
h = A("h")
e = B("e")
d = A("d")

n.t = a
n.y = d
i.r = l
a.r = b
b.t = a
b.y = n
g.r = b
k.r = d
l.t = i
l.y = n
h.t = e
h.y = l
e.r = d
d.t = g
d.y = b
assert g.r.t.r.y.y.txt == "d"