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

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

f = A("f")
h = B("h")
c = B("c")
i = A("i")
b = B("b")
a = A("a")
k = B("k")
d = A("d")
j = B("j")

f.z = d
f.x = b
h.x = b
h.r = c
c.x = j
c.r = b
i.z = d
i.x = c
b.x = j
b.r = k
a.z = f
a.x = b
k.x = j
k.r = b
d.z = a
d.x = h
j.x = c
j.r = k
assert i.x.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.x: B = None
        self.txt = txt

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

f = A("f")
h = B("h")
c = B("c")
i = A("i")
b = B("b")
a = A("a")
k = B("k")
d = A("d")
j = B("j")

f.z = d
f.x = b
h.x = b
h.r = c
c.x = j
c.r = b
i.z = d
i.x = c
b.x = j
b.r = k
a.z = f
a.x = b
k.x = j
k.r = b
d.z = a
d.x = h
j.x = c
j.r = k
assert i.x.r.r.txt == "k"