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

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

j = A("j")
f = B("f")
g = B("g")
d = B("d")
l = A("l")
m = A("m")
n = A("n")
c = A("c")

j.v = f
f.p = g
f.o = d
g.p = d
g.o = f
d.p = f
d.o = g
l.v = f
m.v = f
n.v = g
c.v = g
assert c.v.o.p.p.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

j = A("j")
f = B("f")
g = B("g")
d = B("d")
l = A("l")
m = A("m")
n = A("n")
c = A("c")

j.v = f
f.p = g
f.o = d
g.p = d
g.o = f
d.p = f
d.o = g
l.v = f
m.v = f
n.v = g
c.v = g
assert c.v.o.p.p.o.p.txt == "d"