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

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

g = A("g")
h = B("h")
f = A("f")
e = A("e")
d = B("d")
a = A("a")

g.r = f
g.t = h
h.z = g
h.x = g
f.r = g
f.t = d
e.r = g
e.t = h
d.z = a
d.x = e
a.r = f
a.t = h
assert d.z.r.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: B = None
        self.txt = txt

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

g = A("g")
h = B("h")
f = A("f")
e = A("e")
d = B("d")
a = A("a")

g.r = f
g.t = h
h.z = g
h.x = g
f.r = g
f.t = d
e.r = g
e.t = h
d.z = a
d.x = e
a.r = f
a.t = h
assert d.z.r.r.t.txt == "h"